Skip to content

Instantly share code, notes, and snippets.

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 westonruter/486278 to your computer and use it in GitHub Desktop.
Save westonruter/486278 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Wikipedia TTS-friendly Markup
// @description Include a button in the toolbar on Wikipedia articles to toggle the inclusion of elements not suitable for feeding into a screen-reader.
// @namespace http://weston.ruter.net/
// @include http://en.wikipedia.org/wiki/*
// ==/UserScript==
var noReadEls = [];
Array.forEach(document.querySelectorAll('#bodyContent sup, #toc, .editsection'), function(el){
noReadEls.push(el);
});
function toggleNoReadEls(){
Array.forEach(noReadEls, function(el){
// Toggle off
if(el.parentNode){
var comment = document.createComment(el.textContent);
el.WestonPlaceholder = comment;
el.parentNode.replaceChild(comment, el);
}
// Toggle on
else if(el.WestonPlaceholder){
el.WestonPlaceholder.parentNode.replaceChild(el, el.WestonPlaceholder);
el.WestonPlaceholder = null;
}
});
}
// Add toggle button to page
var btn = document.createElement('button');
btn.type = 'button';
btn.textContent = "Toggle TTS-friendly Markup";
var toolbarRefNode = document.querySelector('#p-views ul > li:first-child');
var li = document.createElement('li');
li.style.cssText = "line-height:40px;";
li.appendChild(btn);
toolbarRefNode.parentNode.insertBefore(li, toolbarRefNode);
btn.addEventListener('click', toggleNoReadEls, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment