Skip to content

Instantly share code, notes, and snippets.

@lwcorp
Last active October 16, 2020 09:56
Show Gist options
  • Save lwcorp/581dfb51b11840aad2e5f75621823117 to your computer and use it in GitHub Desktop.
Save lwcorp/581dfb51b11840aad2e5f75621823117 to your computer and use it in GitHub Desktop.
Bookmarklet - Add Hebrew/RTL support FiveFilters.org's PastePad - when pushing to Kindle/creating files, make the text become right-to-left if it contains Hebrew
javascript:function add_heb_support_prepare(a){var b,c,d,e,f=document.querySelectorAll("input[type=\"submit\"]");for(e=0;e<f.length;e++)f[e].setAttribute("onclick","add_heb_support()");b=`
function add_heb_support() {
var prefix='<html lang="he" />', source_value = CKEDITOR.instances.body.getData(), source = '#cke_contents_body>textarea', source_btn = '#cke_34';
if (document.querySelectorAll(source).length==0)
document.querySelector(source_btn).click();
if(source_value.indexOf(prefix) == -1 && contains_heb(source_value))
CKEDITOR.instances.body.setData(prefix + source_value);
}
function contains_heb(str) {
return (/[\u0590-\u05FF]/).test(str);
}
`,c=document.createElement("SCRIPT"),d=document.createTextNode(b),c.appendChild(d),document.body.appendChild(c),a&&f[0].click()}function checker(){var a;location.hostname=="pastepad.fivefilters.org"?(a=confirm("Would you like push to Kindle?"),add_heb_support_prepare(a)):(alert("Will redirect you, please activate again!"),window.location.href="https://pastepad.fivefilters.org")}checker();
function add_heb_support_prepare(push_now) {
var scr, x, t, i, submit_btn = document.querySelectorAll('input[type="submit"]');
for (i=0; i<submit_btn.length; i++)
submit_btn[i].setAttribute('onclick', 'add_heb_support()');
scr = `
function add_heb_support() {
var prefix='<html lang="he" />', source_value = CKEDITOR.instances.body.getData(), source = '#cke_contents_body>textarea', source_btn = '#cke_34';
if (document.querySelectorAll(source).length==0)
document.querySelector(source_btn).click();
if(source_value.indexOf(prefix) == -1 && contains_heb(source_value))
CKEDITOR.instances.body.setData(prefix + source_value);
}
function contains_heb(str) {
return (/[\u0590-\u05FF]/).test(str);
}
`;
x = document.createElement("SCRIPT");
t = document.createTextNode(scr);
x.appendChild(t);
document.body.appendChild(x);
if (push_now)
submit_btn[0].click()
}
function checker() {
var theroot = "pastepad.fivefilters.org", push_now;
if (location.hostname != theroot) {
alert("Will redirect you, please activate again!")
window.location.href = "https://" + theroot;
} else {
push_now = confirm("Would you like push to Kindle?");
add_heb_support_prepare(push_now);
}
}
checker();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment