Skip to content

Instantly share code, notes, and snippets.

@958
Created January 22, 2009 04:24
Show Gist options
  • Select an option

  • Save 958/50415 to your computer and use it in GitHub Desktop.

Select an option

Save 958/50415 to your computer and use it in GitHub Desktop.
[Sleipnir]kwout for SeaHorse
// ==UserScript==
// @name kwout for SeaHorse
// @description A brilliant way to quote
// @include http://twitter.com/*
// @include http://*jaiku.com/*
// @include http://*tumblr.com/*
// @include http://favotter.matope.com/*
// ==/UserScript==
// modified for seahorse by 958
// base on http://kwout.com/help/greasemonkey
(function(){
function kwout() {
if (window.location.href.match(/^http:\/\/twitter\.com\/.+\/status\/[0-9]+$/)) {
var elements = document.getElementsByTagName('span');
for (var index = 0; index < elements.length; index++) {
if (hasClassAttribute(elements[index], 'entry-meta')) {
appendKwoutButton(elements[index], window.location.href, 'content');
break;
}
}
} else if (window.location.href.match(/^http:\/\/twitter\.com\/.+$/)) {
var elements = document.getElementsByTagName('a');
for (var index = 0; index < elements.length; index++) {
if (hasClassAttribute(elements[index], 'entry-date')) {
appendKwoutButton(elements[index].parentNode, elements[index].getAttribute('href'), 'content');
}
}
} else if (window.location.href.match(/^http:\/\/.+\.jaiku\.com\/presence\/[0-9]+$/)) {
var elements = document.getElementById('current-stream').getElementsByTagName('p');
for (var index = 0; index < elements.length; index++) {
if (hasClassAttribute(elements[index], 'meta')) {
appendKwoutButton(elements[index], window.location.href, 'current-stream');
}
}
} else if (window.location.href.match(/^http:\/\/.+\.jaiku\.com\/$/) || window.location.href == 'http://jaiku.com/') {
var elements = document.getElementsByTagName('p');
for (var index = 0; index < elements.length; index++) {
if (hasClassAttribute(elements[index], 'meta')) {
var h3 = elements[index].parentNode.getElementsByTagName('h3');
if (h3 && h3[0]) {
var a = h3[0].getElementsByTagName('a');
if (a && a[0]) appendKwoutButton(elements[index], a[0].href, 'current-stream');
}
}
}
} else if (window.location.href.match(/^http:\/\/.+\.tumblr\.com\/.*$/)) {
var elements = document.getElementsByTagName('div');
var link = 0;
var quote = 0;
var photo = 0;
var video = 0;
for (var index = 0; index < elements.length; index++) {
if (hasClassAttribute(elements[index], 'link')) {
appendKwoutButton(elements[index], window.location.href, 'link,' + link + '&preset=0');
link++;
} else if (hasClassAttribute(elements[index], 'quote')) {
appendKwoutButton(elements[index], window.location.href, 'quote,' + quote + '&preset=0');
quote++;
} else if (hasClassAttribute(elements[index], 'photo')) {
appendKwoutButton(elements[index], window.location.href, 'photo,' + photo + '&preset=0');
photo++;
} else if (hasClassAttribute(elements[index], 'video')) {
appendKwoutButton(elements[index], window.location.href, 'video,' + video + '&preset=0');
video++;
}
}
} else if (window.location.href.match(/^http:\/\/favotter\.matope\.com\/status\.php\?id=[0-9]+$/)) {
var spans = document.getElementsByTagName('span');
var text = null;
for (var span = 0; span < spans.length; span++) {
if (hasClassAttribute(spans[span], 'status_text')) text = spans[span];
if (hasClassAttribute(spans[span], 'xfolkentry')) {
var as = spans[span].getElementsByTagName('a');
for (var a = 0; a < as.length; a++) {
if (hasClassAttribute(as[a], 'taggedlink')) {
var element = document.createElement('a');
element.href = 'http://kwout.com/grab?address=' + encodeURIComponent(as[a].getAttribute('href')) + '&block=content';
element.target = '_blank';
element.innerHTML = '<img src="http://kwout.com/images/api.gif" alt="kwout this!" title="kwout this!" height="16" width="19" style="border: none; vertical-align: middle;" />';
text.appendChild(element);
break;
}
}
}
}
} else if (window.location.href.match(/^http:\/\/favotter\.matope\.com\/.*$/)) {
var spans = document.getElementsByTagName('span');
var text = null;
for (var span = 0; span < spans.length; span++) {
if (hasClassAttribute(spans[span], 'status_text')) text = spans[span];
if (hasClassAttribute(spans[span], 'xfolkentry')) {
var as = spans[span].getElementsByTagName('a');
for (var a = 0; a < as.length; a++) {
if (hasClassAttribute(as[a], 'taggedlink')) {
var element = document.createElement('a');
element.href = 'http://kwout.com/grab?address=' + encodeURIComponent('http://favotter.matope.com/' + as[a].getAttribute('href')) + '&block=status_' + as[a].getAttribute('href').substr(14);
element.target = '_blank';
element.innerHTML = '<img src="http://kwout.com/images/api.gif" alt="kwout this!" title="kwout this!" height="16" width="19" style="border: none; vertical-align: middle;" />';
text.appendChild(element);
break;
}
}
}
}
}
};
function appendKwoutButton(element, address, block) {
var space = document.createElement('span');
space.innerHTML = '&nbsp;';
var button = document.createElement('a');
button.href = 'http://kwout.com/grab?address=' + encodeURIComponent(address) + '&block=' + block;
button.target = '_blank';
button.style.textDecoration = 'none';
button.innerHTML = '<img src="http://kwout.com/images/api.gif" alt="kwout this!" title="kwout this!" height="16" width="19" style="border: none; vertical-align: middle;" />';
element.appendChild(space);
element.appendChild(button);
};
function hasClassAttribute(element, className) {
var attribute = element.getAttribute('class');
if (!attribute) attribute = element.getAttribute('className');
if (!attribute) return false;
var values = attribute.split(' ');
for (var index = 0; index < values.length; index++) if (values[index] == className) return true;
return false;
};
/*
var version = '1.0.0';
var option = {
url : 'http://kwout.com/gm_version',
method : 'get',
onload : function (response) {
if (response.status == 200) {
GM_setValue('kwout.checked', (new Date()).getTime().toString());
var latest = response.responseText.replace(/[^\d\.]/, '');
kwout();
if (latest != version && GM_getValue('kwout.notified', 'false') != version) {
GM_setValue('kwout.notified', version);
alert('Please update "kwout.user.js" because it has a new version "' + latest +'".');
}
} else {
kwout();
}
},
onerror : function (response) {}
};
var checked = parseInt(GM_getValue('kwout.checked', '0'));
if (checked < (new Date()).getTime() - 3600000) {
GM_xmlhttpRequest(option);
} else {
kwout();
}
*/
kwout();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment