Last active
November 6, 2021 09:51
-
-
Save zero-plusplus/c4bd1eab92db20484acf8456fb41334b to your computer and use it in GitHub Desktop.
For Tampermonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name fixpagetranslate | |
// @namespace | |
// @author zero-plusplus | |
// @include https://* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js | |
// ==/UserScript== | |
(function() { | |
let initedProcessing = false; | |
setTimeout(() => { | |
fixGoogleTranslate() | |
initedProcessing = true; | |
}, 500); | |
let currentUrl = document.location.href; | |
const observer = new MutationObserver(function () { | |
if (initedProcessing && currentUrl !== document.location.href) { | |
fixGoogleTranslate() | |
currentUrl = document.location.href; | |
} | |
}) | |
observer.observe(document, { childList: true, subtree: true }) | |
function fixGoogleTranslate() { | |
$('p, li, td:has(> a)').each((i, element) => { | |
if ($(element).children().length === 1) { | |
return | |
} | |
$(element).children('a').each((i, child) => { | |
$(child).css('display', 'inline'); | |
}) | |
}); | |
$('p, li, td:has(> code)').each((i, element) => { | |
if (0 < $(element).has('code').length) { | |
element.innerHTML = element.innerHTML.replace(/<code[^>]*>|<\/code>/gi, '"'); | |
} | |
}); | |
} | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name notranslate | |
// @namespace | |
// @author zero-plusplus | |
// @include https://* | |
// ==/UserScript== | |
(function() { | |
execNotranslate() | |
function execNotranslate() { | |
try { | |
const codeHighlightClasses = [ | |
'origin', // AutoHotkey code sample | |
'highlight', // [pygments] https://github.com/dagwieers/pygments | |
'prettyprint', // [code-prettify] https://github.com/google/code-prettify | |
'CodeMirror', // [CodeMirror] https://github.com/codemirror/CodeMirror | |
'prism', // [prism] https://github.com/PrismJS/prism | |
'prism-code', | |
'hljs', // [highlight.js] https://github.com/highlightjs/highlight.js/ | |
]; | |
// The syntax highlighting library is excluded from the translation. | |
codeHighlightClasses.forEach(className => { | |
const nodes = document.querySelectorAll(`.${className}`); | |
for (const element of nodes) { | |
element.classList.add('notranslate'); | |
} | |
}); | |
} | |
catch (e) { | |
alert(e.message); | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment