diff --git a/Resources/Plugins/timeline-polls/.meta b/Resources/Plugins/timeline-polls/.meta new file mode 100644 index 00000000..ac20064b --- /dev/null +++ b/Resources/Plugins/timeline-polls/.meta @@ -0,0 +1,15 @@ +[name] +Polls in timelines + +[description] +- Adds poll result display directly into timelines +- Experimental, may be buggy or break when TweetDeck updates + +[author] +chylex + +[version] +1.0 + +[website] +https://tweetduck.chylex.com \ No newline at end of file diff --git a/Resources/Plugins/timeline-polls/browser.js b/Resources/Plugins/timeline-polls/browser.js new file mode 100644 index 00000000..4d14dd9c --- /dev/null +++ b/Resources/Plugins/timeline-polls/browser.js @@ -0,0 +1,34 @@ +constructor(){ + super({ + requiresPageReload: true + }); +} + +enabled(){ + // add a stylesheet + var style = document.createElement("style"); + style.id = "timeline-polls"; + document.head.appendChild(style); + + var sheet = style.sheet; + sheet.insertRule(".column-detail .timeline-poll-container { display: none }", 0); + + // setup layout injecting + this.prevMustaches = {}; + + var injectLayout = (mustache, onlyIfNotFound, search, replace) => { + if (TD.mustaches[mustache].indexOf(onlyIfNotFound) === -1){ + this.prevMustaches[mustache] = TD.mustaches[mustache]; + TD.mustaches[mustache] = TD.mustaches[mustache].replace(search, replace); + } + }; + + // add poll rendering to tweets + injectLayout("status/tweet_single.mustache", "status/poll", "{{/quotedTweetMissing}} {{#translation}}", "{{/quotedTweetMissing}} <div class='timeline-poll-container'>{{>duck/tweet_single/poll}}</div> {{#translation}}"); + TD.mustaches["duck/tweet_single/poll.mustache"] = '<div class="js-poll margin-tl"> {{#poll}} <ul class="margin-b--12"> {{#choices}} <li class="position-rel margin-b--8 height-3"> <div class="poll-bar pin-top height-p--100 br-1 {{#isWinner}}poll-bar--winner{{/isWinner}} {{#hasTimeLeft}}br-left{{/hasTimeLeft}} width-p--{{percentage}}"/> <div class="poll-label position-rel padding-a--4"> <span class="txt-bold txt-right inline-block width-5 padding-r--4">{{percentage}}%</span> {{{label}}} {{#isSelectedChoice}} <i class="icon icon-check txt-size-variable--11"></i> {{/isSelectedChoice}} </div> </li> {{/choices}} </ul> <span class="inline-block txt-small padding-ls txt-seamful-deep-gray"> {{{prettyCount}}} · {{#hasTimeLeft}} {{{prettyTimeLeft}}} {{/hasTimeLeft}} {{^hasTimeLeft}} {{_i}}Final results{{/i}} {{/hasTimeLeft}} </span> {{/poll}} </div>'; +} + +disabled(){ + $("#timeline-polls").remove(); + Object.keys(this.prevMustaches).forEach(mustache => TD.mustaches[mustache] = this.prevMustaches[mustache]); +} \ No newline at end of file