Last active
September 30, 2017 18:34
-
-
Save dennislysenko/b7f1b613b824a3aba342f5881390fb17 to your computer and use it in GitHub Desktop.
Fix memrise for right-to-left languages (developed during an intense Hebrew study session in a café playing Sigur Rós). Userscript - load into Panda Styler or another such extension.
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
function fixBoxes() { | |
// fixes punctuation in a string: mixed LTR/RTL text causes punctuation at the end to appear at the beginning of the string | |
function fix(str) { | |
var match = str.match(/^[\!\?"]+/); // find !, ?, and " at the beginning of a string | |
if (match) { | |
return str.substring(match[0].length) + match[0]; // and move it to the end | |
} | |
return str; | |
} | |
function isHebrew(str) { | |
// ok, this won't hold up to scrutiny, but the main thing is making sure it's not english and this does the job | |
return !str.match(/[a-z]/i); | |
} | |
if (window.location.toString().indexOf("hebrew") != -1) { | |
var selectors = ['#boxes > div > div.thing-show.show-more > div > div.row.column.primary.bigger > div.row-value > div', '#boxes > div > ol > li > span.val.bigger', '#boxes > div > div.question-row.clearfix > div.qquestion.qtext.bigger']; | |
selectors.forEach(function(selector) { | |
if (!isHebrew($(selector).text())) { | |
return; | |
} | |
$(selector).each(function(index, el) { | |
if (!$(el).data('rtl-fixed')) { | |
console.log($(el)); // this won't spam your console, don't worry | |
$(el).css('direction', 'rtl').css('text-align', 'right').attr('dir', 'rtl').attr('direction', 'rtl').css('display', 'inline-block'); | |
$(el).text(fix($(el).text())); // fix punctuation | |
$(el).data('rtl-fixed', true); | |
} | |
}); | |
}); | |
} | |
} | |
setInterval(fixBoxes, 200); // gods this was a hackaround |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment