Skip to content

Instantly share code, notes, and snippets.

Created July 7, 2015 08:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/938de50a24cdc0eef62f to your computer and use it in GitHub Desktop.
Save anonymous/938de50a24cdc0eef62f to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Prevent OBJECT Insertion
// @version 1.1
// @description OBJECT要素の挿入を阻止します。「Amazonが重い」問題(Bug 1172205)を回避できるかもしれません。
// @id f4cce630-3501-4d9f-a846-d69064429f02
// @namespace f4cce630-3501-4d9f-a846-d69064429f02
// @include http://www.amazon.com/*
// @include http://www.amazon.com.au/*
// @include http://www.amazon.com.br/*
// @include http://www.amazon.ca/*
// @include http://www.amazon.cn/*
// @include http://www.amazon.fr/*
// @include http://www.amazon.de/*
// @include http://www.amazon.in/*
// @include http://www.amazon.it/*
// @include http://www.amazon.co.jp/*
// @include http://www.amazon.com.mx/*
// @include http://www.amazon.nl/*
// @include http://www.amazon.es/*
// @include http://www.amazon.co.uk/*
// @grant none
// @run-at document-start
// @noframes
// @copyright No copyright. this program is in the public domain.
// ==/UserScript==
/*
Amazonが重くて且つ「Greasemonkeyを無効にすると軽くなる」という人は
このスクリプトを試す前に、
Greasemonkey本体の設定の「実行しないページ」のリストに
*images-amazon.com/*
を追加してみてください。
設定の場所は ツールバーボタンのメニューの「Greasemonkey オプション(O)...」
または アドオンマネージャ → 拡張機能 → Greasemonkeyの「設定」ボタン
または Alt+T → G → O
*/
/// ChangeLog
// 1.1 <2015-07-07>
// - Scriptish 及び UserScriptLoader.uc.js に対応。
// - 「商品の説明」ページ(IFRAME要素内)では実行されないようにした。
// - insertBefore 関数の書き換えを止めた。
// - ブロックしたOBJECT要素をコンソールログに表示。
// 1.0 <2015-06-12>
// - 公開。
// https://gist.github.com/anonymous/8c1fa6e27eaef2addc80/
// http://anago.2ch.net/test/read.cgi/software/1433432508/773-774n
if (window.frameElement === null) {
var SCRIPT_ID = "f4cce630-3501-4d9f-a846-d69064429f02".toUpperCase();
var script = document.createElement("script");
script.type = "application/javascript";
script.id = SCRIPT_ID;
script.textContent = ' \n\
(function(){ \n\
var TARGET_FUNCTION_NAMES = ["appendChild"]; \n\
var ORIG_SUFFIX = "-ORIGINAL-" + document.currentScript.id; \n\
TARGET_FUNCTION_NAMES.forEach(function(name){ \n\
window.HTMLElement.prototype[name + ORIG_SUFFIX] \n\
= window.HTMLElement.prototype[name]; \n\
window.HTMLElement.prototype[name] = function() { \n\
var node = arguments[0]; \n\
if (node.nodeName !== "OBJECT") \n\
node = this[name + ORIG_SUFFIX].apply(this, arguments); \n\
else { \n\
console.log("Blocked: %o", node); \n\
node = null; \n\
} \n\
return node; \n\
} \n\
}); \n\
})();\n'.replace(/ +$/mg, "");
document.addEventListener("DOMNodeInserted", function(){
var head = document.getElementsByTagName("head").item(0);
if (head && !document.getElementById(SCRIPT_ID)) {
head.appendChild(script);
this.removeEventListener("DOMNodeInserted", arguments.callee, false);
}
}, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment