Skip to content

Instantly share code, notes, and snippets.

@saitamanodoruji
Created April 17, 2011 10:21
Show Gist options
  • Save saitamanodoruji/923920 to your computer and use it in GitHub Desktop.
Save saitamanodoruji/923920 to your computer and use it in GitHub Desktop.
drawr + Tombloo
// ==UserScript==
// @name drawr + Tombloo
// @namespace http://drawr.net/saitamanodoruji
// @description adds 'Tombloo::drawr' command to minibuffer, which calls 'Photo - drawr' extractor of Tombloo.
// @include http://drawr.net/*
// @author saitamanodoruji
// @version 0.0.10
// ==/UserScript==
//
// Features
// -post Photo using Tombloo
// --Command: Tombloo::drawr
// --Shortcutkey: U
//
// -open a drawr user page from a illust page
// --Command: drawr::openUserPage
// --Shortcutkey: O
//
//
// This script ...
// -depends on
// --GM_Tombloo of Tombloo
// --Minibuffer
// --LDRize
// --extractor.drawr.Photo.js https://gist.github.com/923461
//
// -use if exists
// --drawr Bookmark Command Minibuffer https://gist.github.com/254266
// whether post Link using Tombloo
const XPOST_LINK = true
function boot(){
var tombloo = GM_Tombloo.Tombloo.Service
var win = unsafeWindow
var doc = document
var Minibuffer = sharedObject.Minibuffer
var $X = Minibuffer.$X
Minibuffer.addCommand({
name: 'Tombloo::drawr',
command : function(stdin){
Minibuffer.execute('drawr.bookmark', stdin)
var postIndex = 0, totalPostNum = stdin.length
stdin.forEach(function(node){
var ctx = update({
document : doc,
window : win,
target : {
this : $X(
'.//a[contains(@name, "draws")]/img[1]' +
'|' +
'.[contains(@class, "entryArea")]' +
'/div[contains(@class, "entryAreaInner")]' +
'/div[contains(@class, "entryAreaImg")]' +
'/a[1]/img[1]' +
'|' +
'.[contains(@class, "homeBox") or contains(@class, "drawr_box")]' +
'//table//a[1]/img[1]' +
'|' +
'.[contains(@class, "permalinkEntry")]' +
'/div[contains(@class, "floleft")]' +
'/div/a[1]/img[1]'
, node),
src : $X(
'.//a[contains(@name, "draws")]/img[1]' +
'|' +
'.[contains(@class, "entryArea")]' +
'/div[contains(@class, "entryAreaInner")]' +
'/div[contains(@class, "entryAreaImg")]' +
'/a[1]/img[1]' +
'|' +
'.[contains(@class, "homeBox") or contains(@class, "drawr_box")]' +
'//table//a[1]/img[1]' +
'|' +
'.[contains(@class, "permalinkEntry")]' +
'/div[contains(@class, "floleft")]' +
'/div/a[1]/img[1]'
, node)[0].src,
},
event : {},
title : doc.title,
link : $X(
'.[' +
'contains(concat(" ",normalize-space(@class)," ")," homeBox ")' +
' or ' +
'contains(concat(" ",normalize-space(@class)," ")," drawr_box ")' +
' or ' +
'contains(concat(" ",normalize-space(@class)," ")," favoriteBox ")' +
']' +
'//table//a[img]' +
'|' +
'.[contains(concat(" ",normalize-space(@class)," ")," permalinkEntry ")]' +
'/div[contains(concat(" ",normalize-space(@class)," ")," floleft ")]' +
'//a[img]' +
'|' +
'.//div[contains(concat(" ",normalize-space(@class)," ")," entryAreaImg ")]' +
'//a[img]' +
'|' +
'.//div[contains(concat(" ",normalize-space(@class)," ")," threadLink ")]' +
'/a'
, node)[0],
mouse : null,
menu : null,
}, win.location)
var origLink = ctx.link.href
if (ctx.link.href.match(/^http:\/\/drawr\.net\/show\.php\?id=\d+$/)) {
ctx.link.href = ctx.link.href
} else if (ctx.link.href.match(/^(http:\/\/drawr\.net\/show\.php\?id=)\d+#rid(\d+)$/)) {
ctx.link.href = RegExp.$1 + RegExp.$2
} else if (ctx.link.href.match(/^http:\/\/drawr\.net\/show\.php\?id=\d+#$/)) {
ctx.link.href = ctx.href.replace(/#$/, '')
}
if ( /_150x150\.png$/.test(ctx.target.src) )
ctx.target.src = ctx.target.src.replace(/_150x150/, '')
if (!origLink.match(/^http:\/\/drawr\.net\/show\.php\?id=\d+#$/)) {
GM_xmlhttpRequest({
url : ctx.link.href,
method : 'GET',
onload : function(r) {
postIndex++
var illustID = ctx.link.href.match(/^http:\/\/drawr\.net\/show\.php\?id=(\d+)$/)[1]
Minibuffer.status('Tombloo::drawr' + illustID, 'Sharing ' + postIndex + ' of ' + totalPostNum, 500)
ctx.document = Minibuffer.createDocumentFromString(r.responseText)
tombloo.share(ctx, tombloo.extractors['Photo - drawr'], false)
if (XPOST_LINK) {
var ctx_ = update({
document : ctx.document,
target : ctx.document,
window : win,
}, ctx.link)
tombloo.share(ctx_, tombloo.extractors['Link'], false)
}
},
})
}
})
return stdin
}
});
Minibuffer.addShortcutkey({
key: 'U',
description: 'Tombloo::drawr',
command : function(){
try { var stdin = Minibuffer.execute('pinned-or-current-node') } catch(e) { console.log(e) }
Minibuffer.execute('Tombloo::drawr|clear-pin',stdin)
}
});
Minibuffer.addCommand({
name: 'drawr::openUserPage',
command: function(stdin) {
try {
if ( !stdin.length ) stdin = Minibuffer.execute('current-node')
var u = $X(
[ './/div[contains(@class, "drawr_info")]/a[1]',
'|',
'.//div[contains(@class, "floleft")][starts-with(text(), "by")]/a[1]',
'|',
'.//div[contains(@class, "floleft")]/div[starts-with(text(), "by")]/a[1]',
'|',
'.//div[contains(@class, "nameofatie")]//a[1]',
'|',
'.//div[contains(@class, "infoBox")]//a[img[starts-with(@src, "http://cdn05.drawr.net/draw/pf/") or contains(@src, "/images/profile_ss.jpg")]]',
].join('')
, stdin[0])[0].href
GM_openInTab(u, true)
} catch(e) { console.log(e) }
return stdin
},
});
Minibuffer.addShortcutkey({
key: 'O',
description: 'drawr::openUserPage',
command : function(){
try {
Minibuffer.execute('drawr::openUserPage', Minibuffer.execute('current-node'))
} catch(e) { console.log(e) }
}
})
function update(t, s){
for(var p in s)
t[p] = s[p]
return t
}
}
if ( sharedObject.Minibuffer )
boot()
else
window.addEventListener('GM_MinibufferLoaded', boot, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment