-
-
Save mayeaux/c522ae8f8ebcd47825efb18039d4ebcb to your computer and use it in GitHub Desktop.
Bookmarklet to view Twitter poll result without voting
This file contains hidden or 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
( | |
function() { | |
var pod = document.getElementById('permalink-overlay-dialog'); | |
if (!pod) return alert('Not a valid poll'); | |
var iframeList = pod.getElementsByTagName('iframe'); | |
if (iframeList.length === 0) return alert('Not a valid poll'); | |
else if (iframeList.length > 1) return alert('Not a valid poll'); | |
var iframe = iframeList[0]; | |
var innerDoc = iframe.contentDocument || iframe.contentWindow.document; | |
var pollChoices = innerDoc.getElementsByClassName('PollXChoice-choice'); | |
var result = ''; | |
for (var choice of pollChoices) { | |
var choiceData = choice.getElementsByClassName('PollXChoice-choice--text'); | |
var choiceDetailSpan = choiceData && choiceData[0]; | |
var spanList = choiceDetailSpan && choiceDetailSpan.childNodes; | |
if (spanList && spanList.length > 2) { | |
result += spanList[1].textContent + ': ' + spanList[0].textContent + '\n'; | |
} | |
} | |
return alert(result || 'Not a valid poll'); | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment