Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saitamanodoruji/254266 to your computer and use it in GitHub Desktop.
Save saitamanodoruji/254266 to your computer and use it in GitHub Desktop.
drawr Bookmark Command Minibuffer
// ==UserScript==
// @name drawr Bookmark Command Minibuffer
// @namespace http://drawr.net/saitamanodoruji
// @description add drawr bookmark command to Minibuffer
// @include http://drawr.net/*
// @version 0.0.6
// @author saitamanodoruji
// ==/UserScript==
(function() {
var BookmarkShortcutkey = 'F'
var boot = function() {
with (sharedObject.Minibuffer) {
addShortcutkey({
key: BookmarkShortcutkey,
description: 'drawr bookmark',
command: function() {
try { execute( 'drawr.bookmark', execute('pinned-or-current-node')) } catch(e) { console.log(e) }
}
})
addCommand({
name: "drawr.bookmark",
command: function(stdin) {
try {
var bmarks = 0, delbmarks = 0
stdin.forEach(function(s){
// 星アイコンを変更
var star = s.querySelector('a[name=actfav] img')
if ( /icon_bookmark_off\.gif$/.test(star.src) ) {
star.src = star.src.replace(/off(\.gif)$/, 'on$1')
bmarks++
} else if ( /icon_bookmark_on\.gif$/.test(star.src) ) {
star.src = star.src.replace(/on(\.gif)$/, 'off$1')
delbmarks++
}
// ブックマークする
var ar = new (unsafeWindow.Ajax.Request)(star.parentNode.href, {method: "get"})
})
// Minibuffer で "bookmarked N item(s)" って表示させる
var message = "", items_added = 'items', items_removed = 'items'
if (bmarks != 0) {
if (bmarks == 1) items_added = items_added.slice(0, -1)
message += 'bookmarked ' + bmarks + ' ' + items_added
}
if (delbmarks != 0) {
if (bmarks != 0) message += ' & '
if (delbmarks == 1) items_removed = items_removed.slice(0, -1)
message += 'unbookmarked ' + delbmarks + ' ' + items_removed
}
var date = new Date()
status('drawr_bookmark_command' + date.getTime(), message, 100)
execute('clear-pin')
return stdin
} catch(e) { console.log(e) }
return stdin
}})
}
}
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