Created
October 28, 2009 05:20
-
-
Save teramako/220266 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 twittager | |
// @namespace http://twitter.com/teramako/ | |
// @include http://twitter.com/* | |
// @include https://twitter.com/* | |
// ==/UserScript== | |
(function(){ | |
const twittagerNS = new Namespace("http://twittag.r-definition.com/"); | |
var targetScreenName = getTargetScreenName() || getScreenName(); | |
GM_log(targetScreenName); | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: 'http://twittag.r-definition.com/api/get_tags?user_id=' + targetScreenName, | |
onload: function(res){ | |
GM_log(res.responseText); | |
var xml = new XMLList(res.responseText); | |
var tagElms = xml.data.tag; | |
var tag, tags = []; | |
var tagsX = xml.twittagerNS::data.twittagerNS::tag; | |
for (var i = 0, len = tagsX.length(); i < len; i++){ | |
tags.push(tagsX[i].text()); | |
} | |
GM_log("targetScreenName: " + tags.join(",")); | |
setTags(tags); | |
} | |
}); | |
function getScreenName(){ | |
return getMetaContentByName('session-user-screen_name'); | |
} | |
function getTargetScreenName(){ | |
return getMetaContentByName('page-user-screen_name'); | |
} | |
function getMetaContentByName(name){ | |
var elm = document.querySelector("meta[name='" + name + "']"); | |
if (!elm){ | |
return null; | |
} | |
return elm.getAttribute('content'); | |
} | |
function setTags(tags){ | |
if (!tags || !tags.length) { | |
tags = ["none"]; | |
} | |
var profileElm = document.getElementById('profile') | |
var p = document.createElement("p"); | |
p.innerHTML = "Twittag: [" + tags.join("][") + "]"; | |
profileElm.parentNode.insertBefore(p, profileElm.nextSibling); | |
} | |
})(); | |
// vim: sw=2 ts=2 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment