Skip to content

Instantly share code, notes, and snippets.

@xulapp
xulapp / xml2dom.js
Created February 28, 2010 13:37
xml2dom
function xml2dom(xml, doc) {
xml = <root xmlns={ doc.documentElement.namespaceURI }/>.appendChild(xml);
var settings = XML.settings();
XML.prettyPrinting = false;
var root = new DOMParser().parseFromString(xml.toXMLString(), 'application/xml').documentElement;
XML.setSettings(settings);
doc.adoptNode(root);
var range = doc.createRange();
range.selectNodeContents(root);
var frag = range.extractContents();
@xulapp
xulapp / moreToolsMenu.uc.js
Created March 3, 2010 23:49
moreToolsMenu.uc.js
// ==UserScript==
// @name moreToolsMenu.uc.js
// @description adds moreTools-menu to menubar
// @include main
// @compatibility Firefox
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2011/04/03 15:30 +09:00
// ==/UserScript==
@xulapp
xulapp / altTooltip.uc.js
Created April 1, 2010 12:03
altTooltip.uc.js
// ==UserScript==
// @name altTooltip.uc.js
// @description title がなければ alt を出す
// @include main
// @compatibility Firefox 3.5+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2010/04/01 21:00 +09:00
// ==/UserScript==
@xulapp
xulapp / get_function_name.js
Created April 5, 2010 13:03
getFunctionName
function getFunctionName(fn) {
return fn.name || ('' + fn).replace(/^function|\s*\([\s\S]+|(?:\s*\/(?:\/.*|\*[\s\S]*?\*\/)\s*)*/g, '') || 'anonymous';
}
@mathiasbynens
mathiasbynens / wikipedia-remove-sopa-warning.user.js
Created January 18, 2012 07:35
Userscript that removes the SOPA overlay on English Wikipedia
// ==UserScript==
// @name Disable the SOPA overlay on English Wikipedia
// @author Mathias Bynens <http://mathiasbynens.be/>
// @match http://en.wikipedia.org/*
// ==/UserScript==
// http://mths.be/unsafewindow
window.unsafeWindow || (
unsafeWindow = (function() {
var el = document.createElement('p');
@Griever
Griever / abp_jp2urlfilter.ini.js
Created February 22, 2012 09:12
Adblock のフィルタを urlfilter.ini に変換する
javascript:(function(){
/*
Adblock のフィルタを urlfilter.ini に変換する
ついてに広告カット CSS も作成
https://adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt で実行
|| で始まる行は http, https の2行に、^ は "/*" に、$のある行はスルー。
CSS は -moz-document を使っている部分があるので Opera では前半のみ利用可能
*/
@xulapp
xulapp / nyaruko.htm
Created April 18, 2012 14:40
(」・ω・)」うー!(/・ω・)/にゃー!
<body id="B" onload=setInterval('t=new(Date)/210&31;B.innerHTML=28<t?"Let\'s\(・ω・)/にゃー!":["(」・ω・)」うー!","(/・ω・)/にゃー!"][19<t?1:t/4&1]',4)>
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@arnorhs
arnorhs / scroll.js
Created May 17, 2012 08:13 — forked from acrookston/scroll.js
Small scrolling script for fun. Not sure how well it works. Please contribute if you have ideas.
// muhaha.. changed all the code
// maybe this version handles scrolling to the bottom edge of a document a little better
// still not satisfied with the speed variable.. should that be higher == more speed, perhaps? or pixels per second?
// sorry about the opinionated style changes
Scrolling = {
smoothScrollTo: function(target_top) {
// ensure that we never scroll further than viewport size from bottom of the doc
target_top = Math.min(target_top, Math.max($(document).height(), $(window).height()) - $(window).height());
var speed = 30,
@Griever
Griever / Zen2Han.js
Created May 22, 2012 14:01
全角英数を半角英数にするBookmarklet
javascript:/*Zenkaku-Hankaku*/(function(doc){
var zen = /[\u3000\uFFE5\uFF01-\uFF5E]/g;
var arr = ['contains(.,"\u3000")','contains(.,"\uFFE5")'];
for (var i = 0xFF01; i < 0xFF5E; ++i) {
arr.push('contains(.,"' + String.fromCharCode(i) + '")');
}
var xpath = '//text()[(' + arr.join(' or ') + ') and not(ancestor::style) and not(ancestor::script)]';