Skip to content

Instantly share code, notes, and snippets.

@Felipeplz
Last active December 11, 2018 20:59
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 Felipeplz/d41056f5eaa1b6787670a21ddaa7db0e to your computer and use it in GitHub Desktop.
Save Felipeplz/d41056f5eaa1b6787670a21ddaa7db0e to your computer and use it in GitHub Desktop.
Fix for 'twitter-poll-result.js' by vicke4
(
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');
for(var valid_iframe in iframeList){
var iframe = iframeList[valid_iframe];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var pollChoices = innerDoc.getElementsByClassName('PollXChoice-choice');
if(pollChoices.length > 0){
break;
}
}
if(pollChoices.length == 0) return alert('Not a valid poll');
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