-
-
Save noromanba/4236851 to your computer and use it in GitHub Desktop.
kokubunize aka NDKify for UserScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name kokubunizer | |
// @namespace https://flavors.me/noromanba | |
// @description kokubunize aka NDKify for UserScript | |
// @include https://www.facebook.com/* | |
// @downloadURL https://raw.github.com/gist/4236851/kokubunizer.user.js | |
// @installURL https://raw.github.com/gist/4236851/kokubunizer.user.js | |
// @version 2012.12.8.3 | |
// @license WTFPL http://sam.zoy.org/wtfpl/ (Do What The Fuck You Want To Public License) | |
// @contributor udzura https://gist.github.com/4212643 | |
// @author noromanba (http://flavors.me/noromanba) | |
// @homepage https://gist.github.com/4236851 | |
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/New_Bearnstar.png/32px-New_Bearnstar.png | |
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/New_Bearnstar.png/64px-New_Bearnstar.png | |
// ==/UserScript== | |
// Warranty clause http://sam.zoy.org/wtfpl/ | |
/* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. */ | |
// Icon (Public Domain by Lawinc82) | |
// https://commons.wikimedia.org/wiki/File:New_Bearnstar.png | |
// Devel | |
// https://gist.github.com/4236851 | |
// c.f. http://ptech.g.hatena.ne.jp/noromanba/20121207/1354931086 | |
(function () { | |
var slice = Array.prototype.slice; | |
var debounce = function (func, threshould) { | |
var timer; | |
return function () { | |
var context = this, args = slice.call(arguments); | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
func.apply(context, args); | |
}, threshould || 10); | |
}; | |
}; | |
var kokubunize = debounce(function () { | |
var hdif = '今どんな気持ち?', | |
ndk = 'ねえねえ' + hdif; | |
// c.f. http://ptech.g.hatena.ne.jp/noromanba/20120521/1337639496 | |
slice.call(document.querySelectorAll('textarea[placeholder="' + hdif +'"]')).forEach(function (area) { | |
// some browser support c.f. http://help.dottoro.com/ljgugboo.php | |
if (area.placeholder) { | |
area.placeholder = ndk; | |
} else { // XXX redundant, if this block for polyfill, no needed to set @placeholder ...why? | |
area.setAttribute('placeholder', ndk); | |
if (area.value === hdif) { | |
area.value = ndk; | |
} | |
} | |
}); | |
}, 100); | |
// TBD replace to MutationObserver | |
document.addEventListener('DOMNodeInserted', function (evt) { | |
kokubunize(); | |
}, false); | |
})(); | |
// DBG with <at>include http://* | |
// c.f. http://www.ne.jp/asahi/nanto/moon/2010/12/28/placeholder.html | |
// http://webdesignerwall.com/demo/html5-placeholder-text/ | |
/* | |
slice.call(document.querySelectorAll('input[placeholder]')).forEach(function (area) { | |
*/ | |
/*/ | |
var rapidfire = function () { | |
Array.apply(null, Array(100)).forEach(function (_, idx) { | |
console.info('*', _, idx); | |
var input = document.createElement('input'); | |
input.name = idx; | |
input.placeholder = idx; | |
input.value = !!(idx % 2) ? idx : ''; | |
document.body.appendChild(input); | |
}); | |
}; | |
//*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment