├── .github
└── workflows
│ ├── build.yml
│ └── publish.yml
├── .gitignore
├── LICENSE
├── README.md
├── docker-compose.yml
├── package-lock.json
├── package.json
├── rollup.conf.js
└── src
├── index.js
└── main.js
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches: [master]
6 | pull_request:
7 | branches: [master]
8 | workflow_dispatch:
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 |
14 | strategy:
15 | matrix:
16 | node-version: [14.x, 16.x, 18.x]
17 |
18 | name: Node.js ${{ matrix.node-version }}
19 |
20 | steps:
21 | - name: Checkout the project
22 | uses: actions/checkout@v2
23 |
24 | - name: Set up Node.js ${{ matrix.node-version }}
25 | uses: actions/setup-node@v1
26 | with:
27 | node-version: ${{ matrix.node-version }}
28 |
29 | - name: Install dependencies
30 | run: npm ci
31 |
32 | - name: Test the project
33 | run: npm run test --if-present
34 |
35 | - name: Build the project
36 | run: npm run build --if-present
37 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*'
7 |
8 | jobs:
9 | publish:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Checkout the project
14 | uses: actions/checkout@v2
15 |
16 | - name: Set up Node.js
17 | uses: actions/setup-node@v1
18 | with:
19 | node-version: '14.x'
20 |
21 | - name: Install dependencies
22 | run: npm ci
23 |
24 | - name: Build the project
25 | run: npm run build --if-present
26 |
27 | - name: Create release
28 | id: create_release
29 | uses: actions/create-release@v1
30 | env:
31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 | with:
33 | tag_name: ${{ github.ref }}
34 | release_name: ${{ github.ref }}
35 |
36 | - name: Upload userscript to release
37 | uses: actions/upload-release-asset@v1
38 | env:
39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 | with:
41 | upload_url: ${{ steps.create_release.outputs.upload_url }}
42 | asset_path: dist/no-anonymous.user.js
43 | asset_name: no-anonymous.user.js
44 | asset_content_type: application/javascript
45 |
46 | - name: Upload metadata to release
47 | uses: actions/upload-release-asset@v1
48 | env:
49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 | with:
51 | upload_url: ${{ steps.create_release.outputs.upload_url }}
52 | asset_path: dist/no-anonymous.meta.js
53 | asset_name: no-anonymous.meta.js
54 | asset_content_type: application/javascript
55 |
56 | - name: Upload userscript to artifacts
57 | uses: actions/upload-artifact@v2
58 | with:
59 | path: dist/no-anonymous.user.js
60 | name: no-anonymous.user.js
61 | retention-days: 5
62 |
63 | - name: Upload metadata to artifacts
64 | uses: actions/upload-artifact@v2
65 | with:
66 | path: dist/no-anonymous.meta.js
67 | name: no-anonymous.meta.js
68 | retention-days: 5
69 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist
2 | /node_modules
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Dmitriy Trifonov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # No `$$anonymous$$` on Unity Answers
2 |
3 | > :warning: This repository was created as a workaround for a specific problem. The repo is now archived since the problem has been resolved.
4 |
5 | Userscript to replace `$$anonymous$$` tokens on [Unity Answers](https://answers.unity.com/).
6 |
7 |
8 |
9 |
10 |
11 |
12 | See the discussion on the topic here:
13 | [Certain characters and groups of characters get replaced with "$$Anonymous$$"](https://forum.unity.com/threads/certain-characters-and-groups-of-characters-get-replaced-with-anonymous.960722/)
14 |
15 |
16 | ## Installation
17 |
18 | To use userscripts you need to install a userscript manager.
19 | To choose the manager for your browser and platform, see the page:
20 | [Userscript Beginners HOWTO](https://openuserjs.org/about/Userscript-Beginners-HOWTO#how-do-i-get-going-)
21 |
22 | Once you've installed the manager, choose a link below to install the userscript.
23 | [Install directly from GitHub](https://github.com/murphyne/unity-answers-anonymous/releases/latest/download/no-anonymous.user.js)
24 | [Install from Greasy Fork](https://greasyfork.org/en/scripts/427339-eliminate-anonymous)
25 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | dev:
6 | image: node:14
7 | command: bash
8 | working_dir: /usr/src/app
9 | volumes:
10 | - .:/usr/src/app
11 | - /usr/src/app/node_modules/
12 | environment:
13 | - NODE_ENV=development
14 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "unity-answers-anonymous",
3 | "version": "1.0.6",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "@rollup/plugin-virtual": {
8 | "version": "2.0.3",
9 | "resolved": "https://registry.npmjs.org/@rollup/plugin-virtual/-/plugin-virtual-2.0.3.tgz",
10 | "integrity": "sha512-pw6ziJcyjZtntQ//bkad9qXaBx665SgEL8C8KI5wO8G5iU5MPxvdWrQyVaAvjojGm9tJoS8M9Z/EEepbqieYmw==",
11 | "dev": true
12 | },
13 | "fsevents": {
14 | "version": "2.3.2",
15 | "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
16 | "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
17 | "dev": true,
18 | "optional": true
19 | },
20 | "rollup": {
21 | "version": "2.45.2",
22 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.45.2.tgz",
23 | "integrity": "sha512-kRRU7wXzFHUzBIv0GfoFFIN3m9oteY4uAsKllIpQDId5cfnkWF2J130l+27dzDju0E6MScKiV0ZM5Bw8m4blYQ==",
24 | "dev": true,
25 | "requires": {
26 | "fsevents": "~2.3.1"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "unity-answers-anonymous",
3 | "version": "1.0.6",
4 | "description": "Userscript to replace $$anonymous$$ tokens on Unity Answers.",
5 | "license": "MIT",
6 | "author": "murphyne",
7 | "browser": "src/main.js",
8 | "keywords": [
9 | "userscript",
10 | "greasemonkey",
11 | "tampermonkey"
12 | ],
13 | "devDependencies": {
14 | "@rollup/plugin-virtual": "^2.0.3",
15 | "rollup": "^2.45.2"
16 | },
17 | "scripts": {
18 | "build": "rollup -c rollup.conf.js"
19 | },
20 | "homepage": "https://github.com/murphyne/unity-answers-anonymous#readme",
21 | "repository": {
22 | "type": "git",
23 | "url": "git+https://github.com/murphyne/unity-answers-anonymous.git"
24 | },
25 | "bugs": {
26 | "url": "https://github.com/murphyne/unity-answers-anonymous/issues"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/rollup.conf.js:
--------------------------------------------------------------------------------
1 | import virtual from '@rollup/plugin-virtual';
2 | import pkg from './package.json';
3 |
4 | let bannerText = `
5 | // ==UserScript==
6 | // @name Eliminate $$anonymous$$
7 | // @version ${pkg.version}
8 | // @description Replace $$anonymous$$ on Unity Answers!
9 | // @license MIT
10 | // @author murphyne
11 | // @namespace https://github.com/murphyne
12 | // @match https://answers.unity.com/*
13 | // @icon https://www.google.com/s2/favicons?domain=answers.unity.com
14 | // @updateUrl https://github.com/murphyne/unity-answers-anonymous/releases/latest/download/no-anonymous.meta.js
15 | // @downloadUrl https://github.com/murphyne/unity-answers-anonymous/releases/latest/download/no-anonymous.user.js
16 | // @grant GM_addStyle
17 | // @grant GM_registerMenuCommand
18 | // @grant GM_getValue
19 | // @grant GM_setValue
20 | // ==/UserScript==
21 | `;
22 |
23 | export default [
24 | {
25 | input: 'src/main.js',
26 | output: {
27 | file: 'dist/no-anonymous.user.js',
28 | format: 'esm',
29 | banner: bannerText.trimStart(),
30 | },
31 | },
32 | {
33 | input: 'entry',
34 | plugins: [
35 | virtual({ entry: '' }),
36 | ],
37 | output: {
38 | file: 'dist/no-anonymous.meta.js',
39 | banner: bannerText.trim(),
40 | },
41 | },
42 | ];
43 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | export function eliminateAnonymous () {
2 | 'use strict';
3 |
4 | const cssStyle = `
5 | span.anonymous {
6 | -moz-text-decoration-line: underline;
7 | -moz-text-decoration-style: dotted;
8 | -moz-text-decoration-color: brown;
9 | -webkit-text-decoration-line: underline;
10 | -webkit-text-decoration-style: dotted;
11 | -webkit-text-decoration-color: brown;
12 | text-decoration-line: underline;
13 | text-decoration-style: dotted;
14 | text-decoration-color: brown;
15 | text-decoration-thickness: 1px;
16 | text-decoration-skip-ink: none;
17 | }
18 | `;
19 |
20 | function Config(key, defaultValue) {
21 | this.key = key;
22 | this.defaultValue = defaultValue;
23 |
24 | Object.defineProperty(this, "value", {
25 | get() {
26 | return GM_getValue(this.key, defaultValue);
27 | },
28 | set(value) {
29 | GM_setValue(this.key, value);
30 | },
31 | });
32 | }
33 |
34 | let isHighlightEnabled = new Config("isHighlightEnabled", true);
35 |
36 | let style = {
37 | styleElement: null,
38 | set enabled(value) {
39 | if (value) { this.styleElement = GM_addStyle(cssStyle); }
40 | else { this.styleElement?.remove(); }
41 | }
42 | };
43 |
44 | GM_registerMenuCommand('Toggle the highlight', function toggleHighlight () {
45 | isHighlightEnabled.value = !isHighlightEnabled.value;
46 | style.enabled = isHighlightEnabled.value;
47 | });
48 |
49 | style.enabled = isHighlightEnabled.value;
50 |
51 | var replacements = [
52 | [ /(\$\$anonymous\$\$)/g, "hi" ],
53 | ];
54 |
55 | var nodes = traverseNodeTree(document.body).flat(Infinity);
56 | processNodes(nodes);
57 |
58 | const documentObserver = new MutationObserver(function documentCallback (mutations) {
59 | for (let i = 0; i < mutations.length; i++) {
60 | const mutation = mutations[i];
61 | for (let j = 0; j < mutation.addedNodes.length; j++) {
62 | const root = mutation.addedNodes[j];
63 | var nodes = traverseNodeTree(root).flat(Infinity);
64 | processNodes(nodes);
65 | }
66 | }
67 | });
68 | documentObserver.observe(document, {subtree: true, childList: true});
69 |
70 | function processNodes (nodes) {
71 | for (let node of nodes) {
72 | if (node.nodeName === "A") {
73 | if (checkAnonymous(node.href)) {
74 | node.href = replaceAnonymous(node.href);
75 | }
76 | }
77 |
78 | if (node.nodeType === Node.TEXT_NODE) {
79 | if (node.textContent.trim() !== "") {
80 | if (checkAnonymous(node.textContent)) {
81 | let fragment = new DocumentFragment();
82 |
83 | let tokens = tokenize(node.textContent);
84 | for (let token of tokens) {
85 | fragment.appendChild(createNode(token));
86 | }
87 |
88 | node.replaceWith(fragment);
89 | }
90 | }
91 | }
92 | }
93 | }
94 |
95 | function tokenize (textContent) {
96 | let tokens = [{isAnonymous: false, before: textContent, after: textContent}];
97 | for (let replacement of replacements) {
98 | tokens = tokens.flatMap(function (token) {
99 | if (token.isAnonymous) return [token];
100 |
101 | let newStrings = token.after.split(replacement[0]);
102 | return newStrings.map(function (newString) {
103 | return replacement[0].test(newString)
104 | ? {isAnonymous: true, before: newString, after: newString.replaceAll(replacement[0], replacement[1])}
105 | : {isAnonymous: false, before: newString, after: newString}
106 | });
107 | });
108 | }
109 | return tokens;
110 | }
111 |
112 | function createNode (token) {
113 | if (token.isAnonymous) {
114 | let span = document.createElement("span");
115 | span.classList.add("anonymous");
116 | span.textContent = token.after;
117 | span.title = `${token.before} → ${token.after}`;
118 | return span;
119 | }
120 | else {
121 | return document.createTextNode(token.after);
122 | }
123 | }
124 |
125 | function checkAnonymous (str) {
126 | return str.includes("$$anonymous$$");
127 | }
128 |
129 | function replaceAnonymous (str) {
130 | for (let replacement of replacements) {
131 | str = str.replaceAll(replacement[0], replacement[1]);
132 | }
133 | return str;
134 | }
135 |
136 | function traverseNodeTree (root) {
137 | if (root.childNodes.length > 0) {
138 | var childNodes = Array.from(root.childNodes);
139 | var childNodesDeep = childNodes.map(traverseNodeTree);
140 | return [root].concat(childNodesDeep);
141 | }
142 | else {
143 | return [root];
144 | }
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import {
2 | eliminateAnonymous,
3 | } from './index.js';
4 |
5 | eliminateAnonymous();
6 |
--------------------------------------------------------------------------------