Skip to content

Instantly share code, notes, and snippets.

@dennislysenko
Last active September 30, 2017 18:34
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 dennislysenko/b7f1b613b824a3aba342f5881390fb17 to your computer and use it in GitHub Desktop.
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.
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