Skip to content

Instantly share code, notes, and snippets.

@johan
johan / resolveURL.js
Created October 19, 2012 00:17
Resolves a relative url against a base_url using browser internals not exposed to you in API form.
function resolveURL(url, base_url) {
var doc = document
, old_base = doc.getElementsByTagName('base')[0]
, old_href = old_base && old_base.href
, doc_head = doc.head || doc.getElementsByTagName('head')[0]
, our_base = old_base || doc_head.appendChild(doc.createElement('base'))
, resolver = doc.createElement('a')
, resolved_url
;
our_base.href = base_url;
@paulrouget
paulrouget / scratchpad.js
Created August 25, 2012 13:43
How to add custom CSS rules via Scratchpad
/**
* Appends CSS code to an existing stylesheet.
* @param styleSheetURL: URL of an existing styleSheet;
* @param code: CSS code to append.
*/
function appendCSS(styleSheetURL, code) {
let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
Cu.import("resource://gre/modules/NetUtil.jsm");
@nicdaCosta
nicdaCosta / gridBuilder.css
Created August 6, 2012 09:38
This was something i quickly created in "response" to Mootool's JavaScript weekly challenge ( # 1 ) [ http://mootools.net/blog/2012/07/25/javascript-challenge-1/ ] to build a spiraling grid. A live examaple can be seen here - http://jsfiddle.net/TpfCL/
.block{
position:fixed;
display:inline-block;
width:3em;
height:3em;
padding:1em;
margin:0;
background:pink;
border:0.1em solid black;
text-align:center;
@melanke
melanke / MultiGetSet.js
Created June 19, 2012 20:53
MultiGetSet.JS - Quickly generate getters and setters for multiple attributes
var MultiGetSet = function(opt){
var getType = function(o) {
return ({}).toString.call(o).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
};
if(!opt.public || !opt.private)
return opt.public;
if(opt.handler && opt.handler.init)
@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)]';
@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,
@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
);
@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)>
@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 では前半のみ利用可能
*/
@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');