Skip to content

Instantly share code, notes, and snippets.

function saveImage(elem) {// I dont need prompt option
let doc = elem.ownerDocument;
let urlStr = window.makeURLAbsolute(elem.baseURI, elem.src);
let uri = makeURI(urlStr, null, null);
window.urlSecurityCheck(uri, doc.nodePrincipal);
// ?の除去(ファイル名に使えないから)
let tmp = elem.src.replace(/\?/g, '');
let ext = tmp.match(/\/[^\/]+(\.[^.\/]+)$/);
// 拡張子の無いURLの場合
if(ext == null){
key.setCaretKey('z', function(ev){
var frame = document.commandDispatcher.focusedWindow
|| gBrowser.contentWindow;
var selection = frame.getSelection();
var range = frame.document.createRange();
var elem = frame.document.createElement('span');
range.setStart(selection.focusNode, selection.focusOffset);
range.setEnd(selection.focusNode, selection.focusOffset);
elem.innerHTML = "<I>";
elem.setAttribute("style","background-color: green; zIndex: 1000; position:absolute;");
// stop searching by hit Enter on search box
gFindBar.getElement("findbar-textbox")
.addEventListener("keypress", emacslike_search, false);
function emacslike_search(ev){
if(ev.ctrlKey && ev.charCode == 115){ // C-s
gFindBar.onFindAgainCommand(false);
}
if(ev.keyCode == 13){ // Enter
gFindBar.onFindAgainCommand(true);
@hyagni
hyagni / gist:642035
Created October 23, 2010 10:20
change navigation bar color with caret-browse mode in keysnail
key.setViewKey(['C-c', 'C-a'], function (ev) {
children = document.getElementById("nav-bar").children;
for(i=0; i<children.length; i++){
children[i].style.backgroundColor = "pink";
}
util.setBoolPref("accessibility.browsewithcaret", true);
}, "Start Caret-Browse Mode");
key.setCaretKey(['C-c', 'C-a'], function (ev) {
children = document.getElementById("nav-bar").children;
@hyagni
hyagni / keysnail-amazon-BookInfo-Copy.js
Created November 30, 2010 11:22
On amazon pages, copy to clipboard the bookinfo (ASIN, author, title, URL) with C-cC-p
key.setViewKey(['C-c', 'C-p'], function(ev){
var loc = getBrowser().contentDocument.URL;
var doc = frame = document.commandDispatcher.focusedWindow.document
|| gBrowser.contentWindow.document;
if(loc.match(/www\.amazon\./)){
asin = loc.split("/")[5];
r = doc.evaluate("//div[@class='buying']",doc,null,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
list = r.singleNodeValue.textContent.split("\n");
var info = Array();
for(i=0; i<list.length; i++ ){
@hyagni
hyagni / keysnail-open-delicious-bookmark.js
Created November 30, 2010 11:30
Add to delicious bookmark shortcut in keysnail. Bookmarklet like motion.
key.setViewKey(['C-c', 'C-d'], function () {
f='http://www.delicious.com/save?url='+encodeURIComponent(getBrowser().contentDocument.URL)+'&title='+encodeURIComponent(getBrowser().contentDocument.title)+'&v=5&';
a=function(){
if(!window.open(f+'noui=1&jump=doclose','deliciousuiv5','location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))
location.href=f+'jump=yes'
};
if(/Firefox/.test(navigator.userAgent)){
setTimeout(a,0)
} else {
a()
@hyagni
hyagni / brief.patch
Created February 23, 2011 14:24
This patch makes brief gReader-like.
diff -Naur old/content/brief-overlay.xul new/content/brief-overlay.xul
--- old/content/brief-overlay.xul 2010-12-19 04:37:16.000000000 +0900
+++ new/content/brief-overlay.xul 2011-02-23 22:38:31.000000000 +0900
@@ -12,21 +12,21 @@
<key id="Brief_open" key="d" modifiers="accel alt"
oncommand="Brief.open()"/>
- <key id="Brief_selectNextEntry" key="j"
- oncommand="Brief.doCommand('selectNextEntry')"/>
- <key id="Brief_selectPreviousEntry" key="k"
@hyagni
hyagni / use-trash.el
Created February 26, 2011 13:52
On Ubuntu, use trash instead of rm/rmdir. trash is part of trash-cli.
;; use trash for remove files
(defun my-trash-file (FILENAME)
(call-process-shell-command (concat "trash " FILENAME)
nil 0))
;; call-process-shell-command doesnt wait, with BUFFER 0
(defalias 'delete-file 'my-trash-file)
(defalias 'delete-directory 'my-trash-file)
@hyagni
hyagni / get-free-disk-gb.el
Created February 26, 2011 13:57
make get-free-disk-space human readable (especially for dired)
(defadvice get-free-disk-space (after get-free-disk-gb activate)
"Return free disk space with GByte order"
(let ((kb (string-to-number ad-return-value))) ; this is reserved variable
(if (> kb 1024)
(progn (setq kb (/ kb 1024))
(if (> kb 1024)
(setq ad-return-value (format "%.0f GB" (/ kb 1024)))
(setq ad-return-value (format "%.0f MB" kb))))
(setq ad-return-value (format "%.0f kB" kb))
)))
@hyagni
hyagni / command-logger.el
Created February 26, 2011 14:02
logging all the commands
(setq my-log-key-counter 0)
(defun my-log-key (&optional acmd)
(let
((cmd (symbol-name (or acmd this-command)))
(file "~/logging"))
(save-current-buffer
(set-buffer (get-buffer-create "logging"))
(when (= 0 my-log-key-counter)
(insert-file-contents-literally file))
(goto-char (point-max))