Skip to content

Instantly share code, notes, and snippets.

@Griever
Created January 31, 2009 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Griever/55502 to your computer and use it in GitHub Desktop.
Save Griever/55502 to your computer and use it in GitHub Desktop.
No More Scripts 使った方が良いですよ。一応使い方は http://d.hatena.ne.jp/Griever/20090130/1233309871
// ==UserScript==
// @name NoScriptModoki.js
// @namespace http://d.hatena.ne.jp/Griever/
// @version 0.02
// ==/UserScript==
if (NSModoki){
NSModoki._menu = [
{
id : '[nsm_script]',
text : 'Script を許可/拒否',
setting : true
},
{
id : '[nsm_img]',
text : '画像を表示/非表示',
setting : NSModoki._setting.img
},
{
id : '[nsm_embed]',
text : 'embed を表示/非表示',
setting : NSModoki._setting.embed
},
{
id : '[nsm_iframe]',
text : 'iframe を表示/非表示',
setting : NSModoki._setting.iframe
},
];
NSModoki._style = [
{
id : 'style_[nsm_embed]',
css : '{ content: -o-skin("Attachment Video"); } applet{ content: -o-skin("View"); }',
tag : 'embed',
selector : null,
xpath : null,
setting : NSModoki._setting.embed
},
{
id : 'style_[nsm_iframe]',
css : '{ content: -o-skin("Window Document Icon"); }',
tag : 'iframe',
selector : null,
xpath : null,
setting : NSModoki._setting.iframe
},
{
id : 'style_[nsm_img]',
css : '{ content: -o-skin("Disable display images"); }',
tag : 'img',
selector : null,
xpath : null,
setting : NSModoki._setting.img
},
];
NSModoki._styleSheets = {};
NSModoki._iconStyle = null;
NSModoki._icon = null;
//ここから関数
NSModoki.cancel = function(e){ e.preventDefault();}
NSModoki.menuClick = function(e){
var elem = e.currentTarget;
var id = elem.id;
if (elem.className == 'enable'){
elem.className = 'disable';
window.name = window.name.split(id).join('');
}else{
elem.className = 'enable';
window.name += id;
}
if (id == '[nsm_script]'){
location.reload();
}else{
NSModoki._styleSheets['style_' + id].disabled = !NSModoki._styleSheets['style_' + id].disabled;
}
}
NSModoki.showBlockedElement = function(e){
var elem = e.target;
if (elem.localName.toLowerCase() == 'img' || confirm(elem.src + '\n\nこの要素を表示しますか?')){
elem.className += ' show_blocked_element';
elem.removeEventListener('click', arguments.callee, false);
e.preventDefault();
e.stopPropagation();
}
}
NSModoki.DOMLoaded = function(doc){
var XPath = NSModoki._style.filter(function(elem){
return !!elem.setting
}).map(function(elem){
return elem.xpath;
});
var x = doc.evaluate(XPath.join('|'), doc, null, 7, null);
for (var i = 0, elem; elem = x.snapshotItem(i); i++){
if (elem.parentNode instanceof HTMLAnchorElement == false)
elem.addEventListener('click', NSModoki.showBlockedElement, false);
}
}
//1回しか呼ばれない予定の関数
NSModoki.addCSS = function(){
var dElement = document.documentElement;
NSModoki._style.forEach(function(elem){
if (!elem.setting) return;
var style = document.createElement('style');
style.id = elem.id;
style.appendChild(document.createTextNode(
elem.selector + elem.css
));
NSModoki._styleSheets[elem.id] = dElement.appendChild(style);
});
var iconStyle = document.createElement('style')
iconStyle.appendChild(document.createTextNode(
'#nsmodoki_icon {'
+'content: -o-skin("Opera Logo") !important;'
+'position: fixed !important;'
+'bottom: 3px !important;'
+'left: 3px !important;'
+'z-index: 2147483647 !important;'
+'padding:0px !important;'
+'margin:0px !important;'
+'}'
+'#nsmodoki_icon:hover{content: inherit !important;}'
+'#nsmodoki_icon > div{'
+'font-size: 10pt !important;'
+'color:black !important;'
+'background-color: azure !important;'
+'}'
+'#nsmodoki_icon > div:hover{background-color: #ddd !important;}'
+'#nsmodoki_icon > div.enable:before{content: -o-skin("View") !important;}'
+'#nsmodoki_icon > div.disable:before{content: -o-skin("Delete") !important;}'
));
NSModoki._iconStyle = dElement.appendChild(iconStyle);
}
NSModoki.createIcon = function(){
var icon = document.createElement('div');
icon.id = 'nsmodoki_icon';
var windowName = window.name;
NSModoki._menu.forEach(function(menu){
if (!menu.setting) return;
var m = document.createElement('div');
m.id = menu.id;
m.innerHTML = menu.text;
m.className = windowName.indexOf(menu.id) >= 0? 'enable' : 'disable';
icon.appendChild(m);
m.addEventListener('click', NSModoki.menuClick, false);
});
document.documentElement.appendChild(icon);
NSModoki._icon = icon;
}
NSModoki.init = function(){
var full_domain = document.domain;
var match = NSModoki._list.some(function(list){ return full_domain.indexOf(list) >= 0 });
if (match){
document.documentElement.className += ' nsm_loaded';
return;
}
var sec_domain = full_domain.split('.').length > 2?
full_domain.match(/[^/.]+\.(\w\w+|\w\w\.\w\w)$/)[0]:
full_domain;
NSModoki._style.forEach(function(elem){
switch(elem.setting){
case 1 :
elem.xpath = '//'+elem.tag;
elem.selector = elem.tag + ':not(.show_blocked_element)';
break;
case 2 :
elem.xpath = '//'+elem.tag + '[starts-with(@src, "http" )][not(self::*[contains(@src, "'+ sec_domain +'" )])]';
elem.selector = elem.tag + '[src^="http"]:not([src*="'+ sec_domain +'"]):not(.show_blocked_element)';
break;
}
});
NSModoki.addCSS();
document.documentElement.className += ' nsm_loaded';
var windowName = window.name;
if (windowName.indexOf('[nsm_script]') == -1){
opera.addEventListener('BeforeExternalScript', NSModoki.cancel, false);
opera.addEventListener('BeforeScript', NSModoki.cancel, false);
}
if (windowName.indexOf('[nsm_img]') >= 0){
NSModoki._styleSheets['style_[nsm_img]'].disabled = true;
}
if (windowName.indexOf('[nsm_iframe]') >= 0){
NSModoki._styleSheets['style_[nsm_iframe]'].disabled = true;
}
if (windowName.indexOf('[nsm_embed]') >= 0){
NSModoki._styleSheets['style_[nsm_embed]'].disabled = true;
}
document.addEventListener('DOMContentloaded', function(){
NSModoki.createIcon();
NSModoki.DOMLoaded(document);
}, false);
if ("AutoPagerize" in window){
window.AutoPagerize.addFilter(function(docs) {
docs.forEach(NSModoki.DOMLoaded);
});
}
}
NSModoki.init();
}//if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment