Created
November 10, 2016 22:21
-
-
Save pbausch/d37a2d1720bce8533d1e6749d2352d98 to your computer and use it in GitHub Desktop.
Embed Tweets on the Belong.io Page with Tampermonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Belong Tweets | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description add embedded via tweets | |
// @author @pbausch | |
// @match http://belong.io/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var s = document.createElement("script"); | |
s.type = "text/javascript"; | |
s.src = "https://platform.twitter.com/widgets.js"; | |
s.async = true; | |
document.head.append(s); | |
setTimeout(function(){ | |
var bookmarks = document.getElementsByClassName("item-via"); | |
var tweets = new Array(); | |
for(var i = 0; i < bookmarks.length; i++) { | |
var burl = bookmarks[i].childNodes[0].getAttribute("href"); | |
var re = new RegExp("status\/(\\d{15,20})"); | |
var e = re.exec(burl); | |
if (e !== null) { | |
bookmarks[i].childNodes[0].innerHTML += '<div id="t'+ e[1] +'" tweetID="'+ e[1] +'" style="width:500px;"></div>'; | |
var id = e[1]; | |
var tweet = document.getElementById('t'+id); | |
if (!tweets.includes(e[1])) { | |
twttr.widgets.createTweet( | |
id, tweet, | |
{ | |
conversation : 'none', // or all | |
cards : 'visible', // or visible | |
linkColor : '#cc0000', // default is blue | |
theme : 'light' // or dark | |
}); | |
} | |
tweets.push(e[1]); | |
} | |
} | |
}, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment