FANDOM


AntiUnicruft cleans up a nasty set of head-scratching bugs you can get when you do a lot of copy-pasting of code into Common.js, Common.css and other similar files. It automatically strips several magic invisible characters out of your article when you click Publish/Save.

The problem

Unicode (the way text is stored in your computer) provides several invisible 'magic' characters called 'directional marks'. These special characters are used to switch text from Left-to-Right (e.g. Latin languages) to Right-to-Left (e.g. Arabic). These markers let you mix Right-Left and Left-Right languages in a single file which can be useful when working with text... but cause serious problems when working with code (JavaScript or CSS).

If you've ever been in a situation where you're absolutely sure the code is right but it won't work so you retyped it exactly the same and it magically starts working, these evil little invisible characters were the cause. The reason this happens is that sometimes a program will add a Left-Right mark to your clipboard when you copy text and those marks are then pasted into your code. Since the code is already Left-Right, the mark is pointless and redundant; however, the script engine, being a complete pedant, will make a fuss over it and refuse to behave until those marks are removed.

Try copy and pasting the following code into your JavaScript console and run it to see the nastiness in action:

console.log("Confusing, huh?‎" === "Confusing, huh?");

Installation

Install UnsafeScripts for this script to work on JavaScript pages in MediaWiki and User namespace! For security reasons, FANDOM has disabled custom JavaScript from running on MediaWiki and User namespace pages that end with .js or .css, but a JavaScript and CSS editor is available on these pages which makes the tab key insert four spaces.

Operational Notes

The script will only run on Article pages whose names end with '.js' or '.css'. For example, it will run on 'MediaWiki:Common.js', 'User:You/global.js', 'Template:Something/appearance.css'. It will not run on anything that does not have those file extensions (this is a protection mechanism to avoid breaking articles that use directional marks intentionally).