Skip to content

Instantly share code, notes, and snippets.

@gaogao-9
Last active December 21, 2015 17:14
Show Gist options
  • Save gaogao-9/6651d276f7ea80288833 to your computer and use it in GitHub Desktop.
Save gaogao-9/6651d276f7ea80288833 to your computer and use it in GitHub Desktop.
いわゆるテンプレ
// ==UserScript==
// @name ユーザースクリプトの名前をここに入力
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author あなたの名前をここに
// @match http://www.want_to_match-url.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function(){
main(function(){
"use strict";
// この中にやりたい処理を全部記述していく
});
function main(callback){
var limit = 30;
(function loop(){
// 一定回数以上ループしてしまったら、中断する(無限ループ対策)
if(limit--) return;
// DOMの取得が完了してなければループして待機
if(document.head === null){
setTimeout(loop,0);
return;
}
// スクリプトを埋め込む
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.head.appendChild(script);
})();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment