TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: I wrote a bookmarklet to know any Twitter poll result without your vote

2 点作者 vicke4超过 4 年前

2 条评论

blindm超过 4 年前
And here&#x27;s the code if anyone is interested in how it works:<p><pre><code> javascript:!function(){if(&#x27;https:&#x2F;&#x2F;twitter.com&#x27;!==window.location.origin||4!==window.location.pathname.split(&#x27;&#x2F;&#x27;).length)return alert(&#x27;This is not a valid Twitter poll!&#x27;);alert(&#x27;Please wait this can take up to 30 seconds. Select OK or close to get started. If this is a valid poll, you will get the result when it is ready...:)&#x27;);let t=&#x27;&#x27;,e=!1,o=window.XMLHttpRequest.prototype.open;const i=Date.now();window.XMLHttpRequest.prototype.open=function(){if(e)return o.apply(this,arguments);function n(){try{if(this.responseURL.includes(&#x27;poll&#x27;)){const e=JSON.parse(this.responseText).card.binding_values,o=Object.keys(e).reduce(function(t,o){if(o.includes(&#x27;_label&#x27;)){const i=e[o].string_value,n=o.replace(&#x2F;\D&#x2F;g,&#x27;&#x27;),s=e[`choice${n}_count`].string_value;t.choiceVoteCountMap[i]=+s,t.noOfVotes+=+s}return t},{noOfVotes:0,choiceVoteCountMap:{}}),{choiceVoteCountMap:i,noOfVotes:n}=o;Object.keys(i).forEach(function(e){t+=`${e}: ${(i[e]&#x2F;n*100).toFixed(2)}%\n`})}}catch(t){e=!0,window.confirm(&#x27;Something went wrong. Could you please report the issue?&#x27;)&amp;&amp;window.open(&#x27;https:&#x2F;&#x2F;www.syncwithtech.org&#x2F;twitter-poll-result-wo-voting&#x2F;&#x27;,&#x27;_blank&#x27;),this.removeEventListener(&#x27;load&#x27;,n)}}return this.addEventListener(&#x27;load&#x27;,n),t&amp;&amp;(e=!0,alert(t),this.removeEventListener(&#x27;load&#x27;,n)),Date.now()-i&gt;4e4&amp;&amp;!e&amp;&amp;(e=!0,window.confirm(&#x27;Seems like it is not a valid Twitter poll. Press OK to report the issue if it is a valid poll and the bookmarklet failed to detect it.&#x27;)&amp;&amp;window.open(&#x27;https:&#x2F;&#x2F;www.syncwithtech.org&#x2F;twitter-poll-result-wo-voting&#x2F;&#x27;,&#x27;_blank&#x27;),this.removeEventListener(&#x27;load&#x27;,n)),o.apply(this,arguments)}}();</code></pre>
评论 #24333639 未加载
vicke4超过 4 年前
Hey guys,<p>I wanted to check the Twitter poll results before voting for one of the choices. So, I wrote a bookmarklet which opens an alert with the poll results when used on an ongoing Twitter poll page. The script just intercepts the API requests Twitter make to fetch poll results every 30 seconds and populates the result. You can find the script as a gist: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;vicke4&#x2F;891b14bbf46f247fb7314cb3565d1797" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;vicke4&#x2F;891b14bbf46f247fb7314cb3565d1...</a><p>To test the bookmarklet you need to find a poll. You can get only polls as results when you search for one of the below queries,<p>card_name:poll2choice_text_only<p>card_name:poll3choice_text_only<p>card_name:poll4choice_text_only<p>card_name:poll2choice_image<p>card_name:poll3choice_image<p>card_name:poll4choice_image<p>On the mobile app, you can just turn off your data&#x2F;WiFi and select one of the choices, you&#x27;ll be able to see the results for a moment.