User:Tale glider/common.js
From VNDev Wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
function highlight_words(do_highlight){ target_class = "highwords" if (do_highlight){ target_class = "highwords highlighted_phrase" } console.log("Looking for spans"); var highwords=document.getElementsByClassName("highwords"); console.log("Found them") for (let elem_pos=0; elem_pos<highwords.length; elem_pos++){ elem = highwords[elem_pos];//.class="highlighted_phrase"; elem.className=target_class; } } function make_highlight_buttons(){ var content_div = document.getElementById("bodyContent"); var first_content = content_div.firstElementChild; var toggler_div = document.createElement("div"); toggler_div.innerHTML="<button type=\"button\" onclick=\"highlight_words(true)\">Highlight important words</button><br><button type=\"button\" onclick=\"highlight_words(false)\">Unhighlight important words</button>"; content_div.insertBefore(toggler_div, first_content); } $(document).ready(make_highlight_buttons);