Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Allow to toggle the highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
murphyne committed May 30, 2021
1 parent a621e3d commit bd56203
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-answers-anonymous",
"version": "0.4.0",
"version": "1.0.0",
"description": "Userscript to replace $$anonymous$$ tokens on Unity Answers.",
"license": "MIT",
"author": "murphyne",
Expand Down
5 changes: 4 additions & 1 deletion rollup.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import virtual from '@rollup/plugin-virtual';
let bannerText = `
// ==UserScript==
// @name Eliminate $$anonymous$$
// @version 0.4.0
// @version 1.0.0
// @description Replace $$anonymous$$ on Unity Answers!
// @license MIT
// @author murphyne
Expand All @@ -12,6 +12,9 @@ let bannerText = `
// @updateUrl https://github.com/murphyne/unity-answers-anonymous/releases/latest/download/no-anonymous.meta.js
// @downloadUrl https://github.com/murphyne/unity-answers-anonymous/releases/latest/download/no-anonymous.user.js
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
`;

Expand Down
35 changes: 33 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function eliminateAnonymous () {
'use strict';

GM_addStyle(`
const cssStyle = `
span.anonymous {
-moz-text-decoration-line: underline;
-moz-text-decoration-style: dotted;
Expand All @@ -15,7 +15,38 @@ export function eliminateAnonymous () {
text-decoration-thickness: 1px;
text-decoration-skip-ink: none;
}
`);
`;

function Config(key, defaultValue) {
this.key = key;
this.defaultValue = defaultValue;

Object.defineProperty(this, "value", {
get() {
return GM_getValue(this.key, defaultValue);
},
set(value) {
GM_setValue(this.key, value);
},
});
}

let isHighlightEnabled = new Config("isHighlightEnabled", true);

let style = {
styleElement: null,
set enabled(value) {
if (value) { this.styleElement = GM_addStyle(cssStyle); }
else { this.styleElement?.remove(); }
}
};

GM_registerMenuCommand('Toggle the highlight', function toggleHighlight () {
isHighlightEnabled.value = !isHighlightEnabled.value;
style.enabled = isHighlightEnabled.value;
});

style.enabled = isHighlightEnabled.value;

var replacements = [
[ /(\$\$anonymous\$\$onoBehaviour)/g, "MonoBehaviour" ],
Expand Down

0 comments on commit bd56203

Please sign in to comment.