Created
July 22, 2010 17:19
-
-
Save westonruter/486278 to your computer and use it in GitHub Desktop.
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
// ==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