Original link: https://www.zhangxinxu.com/wordpress/2023/03/js-disorder-chinese/
by zhangxinxu from https://www.zhangxinxu.com/wordpress/?p=10791 Xin space – Xin life
This article is welcome to share and aggregate, there is no need to reprint the full text, respect copyright, the circle is so big, if you need it urgently, you can contact for authorization.
1. Text protection whim
Suddenly, I wrote a piece of JS to make the Chinese content weird. It seems to read normally, but when I look closely, it is full of mistakes.
Can be used to protect text content.
For example, the content of the article does not want the other party to copy it. Many people’s practice is to prohibit right-clicking and selection. This experience is not good.
There are also some websites that add a copyright description at the end of the copied content. The code indicates:
document. addEventListener('copy', function (event) { var clipboardData = event.clipboardData || window.clipboardData; if (!clipboardData) { return; } var text = window. getSelection(). toString(); if (text) { event. preventDefault(); clipboardData.setData('text/plain', text + '\n\nXin space copyright'); } })
These are the more popular methods in the market at present, but the popular ones are not necessarily the most suitable ones. If some errors that are not easy to find (such as common typos and key word meaning reversals) are quietly made in the copied content, the effect Should be better because it’s more hidden.
Just do it, take advantage of the free time on Sunday, and the code will be picked up.
2. Rough implementation
The idea is as follows, the numbers change randomly, “you, me, him” and “dedide” are randomly mapped, and then some words have antonyms.
For the antonym, I thought of getting a Chinese antonym database, and after searching, there is a corresponding Github document, see here .
There are a huge number of antonyms in it, and it is obviously not possible to use all of them. First, it is unnecessary, second, its performance is poor, and third, it requires relatively high technical requirements, so it is not worthwhile.
So, just need an antonym of a single word and that’s it.
Then process it into the required one-to-one key-value mapping object, that’s it.
Here’s the JavaScript code for the implementation:
String.prototype.disorder = function () { // The code is a little... ? }
The implementation is very simple. Assuming that the original correct text variable name is text, the obfuscated code can be expressed as follows:
const textDisorder = text. disorder();
Case presentation
I found a piece of news without any nutrition:
On March 18, Yu Minhong shared his business mind in Yabuli with the theme of “Never Give Up”. He talked about the “knowledge sharing” live broadcast selected by Dongfang. I completely despise the howling of buying, buying and buying.
Yu Minhong believes that live streaming should be a kind of calm and knowledgeable explanation of the product, and other knowledge can be disseminated in addition to the explanation.
“So I did the first selection of Dongfang. At that time, New Oriental didn’t know how to choose products. They chose the most expensive agricultural products in China, but I still held the map, the geography book, and the history book. , and told the first batch of buyers selected by the East in detail about the mining area of each product and the history of this mining area.” He said.
Then use the written JS to moisten it, the result is:
The meaning is generally understood, but it is inexplicable to read, hahaha.
However, judging from the case, the text confusion hit rate is still very high, in fact, it should be reduced by another 50%, because there is too much confusion now, it is already too obvious.
You can modify the probability or the number of mapped characters in the JS code according to actual usage requirements.
Oh, I forgot to show the JS code, you can click here hard: Chinese content becomes confusing to read demo
The implementation source code is on the demo page with red text above, and the probability mentioned above can be modified by referring to the code position shown in the figure below. Currently, the probability is 50%:
3. How to use and field test
The method of use is as follows:
- Import the corresponding JS file:
<script src="./disorder.js"></script>
- Input and output of the target character:
strTo = strFrom. disorder();
over~
OK, back to the scene mentioned at the beginning, copy text content interference.
I quietly introduced the corresponding JS on this document page, and bound the JS code as shown below:
document. addEventListener('copy', function (event) { var clipboardData = event.clipboardData || window.clipboardData; if (!clipboardData) { return; } var text = window. getSelection(). toString(); if (text) { event. preventDefault(); clipboardData.setData('text/plain', text.disorder()); } })
Therefore, you can try to copy the text content of this article, and then find a place to paste it to see if the content of the copy is slightly different, hehehe~
Then, the code shown in this article is not the best implementation, because it is obvious that some words and sentences cannot be read after replacing the antonyms. The combination of Chinese intelligent lexical analysis achieves the best results.
In a word, this article focuses on attracting jade.
Four, chat for a while
I have been to Shanghai for so many years, and it was the first time I went to Jinshan yesterday. I went to Fengjing Town, but I didn’t go to the ancient town. The ancient towns in Jiangsu, Shanghai and Zhejiang are basically carved out of the same mold. It’s not interesting. I went to paint. In the village, there is an exhibition of farmers’ names, and there is a Polish upside-down house, all of which are 25 people.
The upside-down house houses are all upside down, and the ground is sloped, which is very suitable for taking some special effects photos.
It just looks like the kind that stands upside down. Let me show you some pictures.
There is a fishing place more than 700 meters away, called “Hefeng Fishing Resort”, there is a place where you can fish, 30 yuan an hour, the fish is small and the price is expensive, but the environment is good, you can only fish for two hours, I personally I prefer this kind of fishing spot. It doesn’t matter if it’s expensive. The important thing is that there are few people and the environment is good. This place meets my needs.
How about the specific environment? You can watch my Douyin video. Welcome to follow my Douyin account and share fishing life every week.
This article is an original article, welcome to share, do not reprint the full text, if you really like it, you can bookmark it, it will never expire, and will update knowledge points and correct errors in time, and the reading experience will be better.
Address of this article: https://www.zhangxinxu.com/wordpress/?p=10791
(End of this article)
This article is transferred from: https://www.zhangxinxu.com/wordpress/2023/03/js-disorder-chinese/
This site is only for collection, and the copyright belongs to the original author.