Skip to content

Instantly share code, notes, and snippets.

@pbausch
Last active December 20, 2016 03:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pbausch/f3aa676f89a5f302464435b363e21aab to your computer and use it in GitHub Desktop.
Save pbausch/f3aa676f89a5f302464435b363e21aab to your computer and use it in GitHub Desktop.
Embed Tweets on the Pinboard Popular Page with Tampermonkey
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description embed tweets on Pinboard Popular page
// @author You
// @match https://pinboard.in/popular/
// @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("bookmark_title");
var tweets = new Array();
for(var i = 0; i < bookmarks.length; i++) {
var burl = bookmarks[i].getAttribute("href");
var re = new RegExp("status\/(\\d{15,20})");
var e = re.exec(burl);
if (e !== null) {
bookmarks[i].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