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:
parent
221bdc58fe
commit
6636a2aa9e
Resources/Plugins/timeline-polls
15
Resources/Plugins/timeline-polls/.meta
Normal file
15
Resources/Plugins/timeline-polls/.meta
Normal 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
|
34
Resources/Plugins/timeline-polls/browser.js
Normal file
34
Resources/Plugins/timeline-polls/browser.js
Normal 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}}} · {{#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]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user