Skip to content

Instantly share code, notes, and snippets.

@Ereza
Last active March 5, 2020 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ereza/f083f09cc17f84c4b62511c4718adb6c to your computer and use it in GitHub Desktop.
Save Ereza/f083f09cc17f84c4b62511c4718adb6c to your computer and use it in GitHub Desktop.
Zelda3 preview in Weblate for TamperMonkey
// ==UserScript==
// @name The Legend of Zelda: A Link to the Past preview for Weblate
// @namespace https://traduccions.ereza.cat/
// @version 0.0.2
// @description The Legend of Zelda: A Link to the Past preview for Weblate
// @author Eduard Ereza Martínez
// @match https://weblate.ereza.cat/translate/the-legend-of-zelda-a-link-to-the-past/textos/*/*
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle("@font-face { font-family: 'return_of_ganonregular'; src: url('https://www.ereza.cat/personal/phpzel3/returnofganonreg-v1-webfont.woff2') format('woff2'), url('https://www.ereza.cat/personal/phpzel3/returnofganonreg-v1-webfont.woff') format('woff'); font-weight: normal; font-style: normal; }");
function parseZeldaPreviewText(text){
text = text.replace(/{empty}/g,"");
text = text.replace(/{NextPic}/g,"");
text = text.replace(/{Choose23}/g,"");
text = text.replace(/{Item}/g,"");
text = text.replace(/{Name}/g,"WWWWWW");
text = text.replace(/{Window:..}/g,"");
text = text.replace(/{Number:..}/g,"9");
text = text.replace(/{Position:..}/g,"");
text = text.replace(/{ScrollSpd:..}/g,"");
text = text.replace(/{SelChng}/g,"");
text = text.replace(/{Choose12}/g,"");
text = text.replace(/{Choose123}/g,"");
text = text.replace(/{Scroll}/g,"\n");
text = text.replace(/{Line1}/g,"");
text = text.replace(/{Line2}/g,"\n");
text = text.replace(/{Line3}/g,"\n");
text = text.replace(/{Color:..}/g,"");
text = text.replace(/{Wait:..}/g,"");
text = text.replace(/{Sound:..}/g,"");
text = text.replace(/{Speed:..}/g,"");
text = text.replace(/{WaitKey}/g,"⏎");
text = text.replace(/{Byte:8A}/g,"  ");
text = text.replace(/{Byte:89}/g,"   ");
text = text.replace(/{Byte:88}/g,"    ");
text = text.replace(/{Byte:..}/g,"");
text = text.replace(/{HEART_._.}/g,"W");
text = text.replace(/{LINK1}{LINK2}/g,"@");
text = text.replace(/➡/g,">");
text = text.replace(/☥/g,"`");
text = text.replace(/〜/g,"^");
text = text.replace(/⦚/g,"~");
text = text.replace(/↑/g,"W");
text = text.replace(/←/g,"W");
text = text.replace(/↓/g,"w");
text = text.replace(/→/g,"W");
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br />");
return text;
}
function applyZeldaPreview(){
var textarea = document.getElementsByName('target_0')[0];
var preview = document.getElementById('zeldapreview');
preview.innerHTML=parseZeldaPreviewText(textarea.value);
}
(function() {
'use strict';
if (document.getElementsByName('target_0').length>0){
var textarea = document.getElementsByName('target_0')[0];
var root = document.getElementsByName('fuzzy')[0].parentElement.parentElement.parentElement.parentElement;
var myElement = document.createElement("div");
myElement.innerHTML='<label>Previsualització</label><div id="zeldapreview" style="width: 390px; overflow-x: hidden; height: 172px; background-image: url(\'https://www.ereza.cat/personal/phpzel3/bg.png\'); background-repeat: no-repeat; font-family: \'return_of_ganonregular\'; font-size: 32px; padding-left: 16px; padding-top: 14px; padding-bottom: 14px; color: white; text-shadow: black 2px 2px 1px; white-space: nowrap; line-height: 32px; box-sizing: border-box;" />';
root.appendChild(myElement);
setTimeout(function() {
//Copied from Weblate
$('.specialchar').click(function (e) {
applyZeldaPreview();
});
$('.copy-text').click(function (e) {
applyZeldaPreview();
});
}, 100);
textarea.addEventListener('input', function() {
applyZeldaPreview();
});
applyZeldaPreview();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment