1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-22 18:15:47 +02:00

Add an experimental timeline-polls plugin

This commit is contained in:
chylex 2016-09-23 19:49:56 +02:00
parent 221bdc58fe
commit 6636a2aa9e
2 changed files with 49 additions and 0 deletions
Resources/Plugins/timeline-polls

View File

@ -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

View File

@ -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}}} &middot; {{#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]);
}