Thread: Trying to force and Opera userjs to work in Midori...
so, don't know javascript, , less inner workings of midori.
here userjs got opera forums:
i replaced 1 instance of "opera" "midori" , googled make sure makes sense, , does.code:// ==userscript== // @name blockit, noscript extension firefox, different. // @author shoust // @version 1.5 // @description best way describe extension firefox, noscript extension firefox allows selective blocking/unblocking of scripts in page, same , more, allows blocking/unblocking of iframes,embedded content , images well, plus default, keeps elements based on site unblocked, things not based on site blocked. // @include * // ==/userscript== (function() { if (location.hash != '#nsoff' && !window.name.match(/#nsoff/) && !location.href.match(/\.(svgz?|jpe?g|js|txt|png|gif|bmp|css)$/)) { /*check if script needs executed. */ var cornerposition = 4; // 1 = top left, 2=top right , 3=bottom left , 4=bottom right etc, makes button show options in either top or bottom of page. var blocksiteresources = false; // option allows blocking of scripts based on site, if false, resources residing on http://my.opera.com on http://my.opera.com/community/ won't blocked example. var imgblockit = false; var iframeblockit = true; var mediablockit = true; function createcookie(name, value, days, addition, forpage) /* saving settings cookies. "addition" variable add settings cookie, instead of removing whole cookie altogether*/ { if (!forpage) /*saving settings page/pathname only,instead of whole site*/ { var x = escape(location.pathname); x = x.replace(/\//g, '__').replace(/\./g, '--'); } if (name != 'noresource') name = 'no' + activeselect(); if (days) { var date = new date(); date.settime(date.gettime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.togmtstring(); } else var expires = ""; document.cookie = name + (!forpage ? x: '') + "=" + value + (addition ? ' ' + addition: '') + expires + "; path=/"; } function readcookie(name, forpage) /*for reading settings*/ { if (!forpage) /*reading settings page/pathname only,instead of whole site*/ { var x = escape(location.pathname); x = x.replace(/\//g, '__').replace(/\./g, '--'); } var nameeq = (forpage == 'g' ? name: name + x) + "="; var ca = document.cookie.split(';'); ( var = 0; < ca.length; i++) { var c = ca[i]; while (c.charat(0) == ' ') c = c.substring(1, c.length); if (c.indexof(nameeq) == 0) return c.substring(nameeq.length, c.length); } return ''; } function erasecookie(name) { createcookie(name + activeselect(), "", -1); } // deleting settings /* work out elements being selected block @ right time*/ function activeselect() { var x = document.getelementbyid('ujs42-_noelementselect'); return (x ? x[x.selectedindex].value: 'script'); } /* function generate element block list iframes, embeds , images in page. */ function generatelist(name) { var elementz = document.selectnodes('//' + name + '[@src]'); if (!elementz.length) { //if no elements on page, nothing else. return; } var count = elementz.length; var forpage = readcookie('no' + name) ? readcookie('no' + name) : ''; //settings page var forsite = readcookie('no' + name, 'g') ? readcookie('no' + name, 'g') : ''; //settings site var forserverunblock = readcookie('noresource', 'g') ? readcookie('noresource', 'g') : ''; var listselect = document.createelement('select'); //the list of elements , urls block listselect.onchange = blocktoggle; listselect.id = "ujs42-_no" + name + "select"; listselect.style = 'width:300px;display:none;margin-right:20px !important;'; var host = location.hostname; ( var = elementz.length - 1; >= 0, element = elementz[i]; i--) { var link = document.createelement('a'); //just way hostname without using match or indexof. link.href = (element.src ? element.src: element.getattribute('src')); var linkhost = link.hostname; elemcount = + 's'; // unique identifier in document's order block element or unblock element. var listoption = document.createelement('option'); listoption.value = elemcount; listoption.innertext = (element.src ? element.src: element.getattribute('src')); listoption.setattribute('title', linkhost); //unique server identifier block or unblock server listoption.setattribute('alt', element.currentstyle.display); if (!blocksiteresources && linkhost == host) { count--; // not display elements same site if blocksiteresources off. } else if (link.href.indexof('data:') == 0) { count--; // not display elements starting data: } else if ((forpage && forpage.indexof(elemcount.tostring()) != -1) || (forsite && forsite.indexof(linkhost) != -1) || (forserverunblock && forserverunblock.indexof(linkhost) != -1)) { // unblock elements if match cookie says unblock them showasblocked_unblocked(listoption); listselect.appendchild(listoption); } else { //blocks element. element.style.display = 'none'; showasblocked_unblocked(listoption, 'x'); listselect.appendchild(listoption); } } if (count != 0) { //if elements needed blocked zero, don't display option block list of elements. var elemselect = document.createelement('option'); elemselect.innertext = (name == 'img' ? 'images': name == 'embed' ? 'embeds(media)': name == 'iframe' ? 'iframes': '') + '(' + count + ',' + elementz.length + ')'; elemselect.value = name; return [elemselect,listselect]; } } function showelementlist() { //this function toggle between element lists block , unblock var elemlist = ['img', 'embed', 'iframe', 'script']; var element = this.value; var elemselect = document.getelementbyid('ujs42-_no' + element + 'select'); ( var = elemlist.length - 1; >= 0, elemtag = elemlist[i]; i--) if (elemtag == element) { elemselect.style.display = 'inline'; } else if (document.getelementbyid('ujs42-_no' + elemtag + 'select')) { document.getelementbyid('ujs42-_no' + elemtag + 'select').style.display = 'none'; } if (elemselect && elemselect.disabled == false) blocktoggle(); } function showasblocked_unblocked(element, block, bringback, single) { //function show if element blocked or unblocked in ui. var notblocked = (element.innertext.indexof('#x# -') == 0); var noscriptelement = document.getelementbyid('ujs42-_noscriptselect'); if (!notblocked && block == 'x') { if ((noscriptelement && noscriptelement.style.display == 'none') || !noscriptelement && single) { var highlight = document.selectsinglenode('//*[@src="' + element.innertext + '"]'); if(highlight) {highlight.style.outlinecolor = 'red'; highlight.style.outlinestyle = 'dashed'; settimeout(function() { highlight.style.outlinestyle = 'none'; highlight.style.display = 'none'; }, 500); }} element.innertext = '#x# -' + element.innertext; } else if (notblocked && !block) { element.innertext = element.innertext.substr(5); if ((noscriptelement && noscriptelement.style.display == 'none') || !noscriptelement && single) { var highlight = document.selectsinglenode('//*[@src="' + element.innertext + '"]'); if(highlight){highlight.style.display = element.getattribute('alt'); highlight.style.outlinecolor = 'orange'; highlight.style.outlinestyle = 'dashed'; settimeout(function() { highlight.style.outlinestyle = 'none'; }, 500); if (single == '1') { highlight.scrollintoview(true); }} } } if (bringback) { return element } } function block_unblock() { //the function write stuff needed unblock cookie. var optionelement = document.getelementbyid('ujs42-_no' + activeselect() + 'select'); var whattoblock = (event.ctrlkey || this.value == 'server') ? optionelement[optionelement.selectedindex].getattribute('title') : (event.shiftkey || this.value == 'all') ? '': optionelement.value; var unblockonly = event.altkey; var whatservertounblock = (event.ctrlkey && this.value == 'server'); var forpage = readcookie('no' + activeselect()) ? readcookie('no' + activeselect()) : ''; //for page only, doesn't affect other pages on same site var forsite = readcookie('no' + activeselect(), 'g') ? readcookie('no' + activeselect(), 'g') : ''; //for whole site, unblock servers. var forserverunblock = readcookie('noresource', 'g') ? readcookie('noresource', 'g') : ''; if (document.getelementbyid('ujs42-_nelbb').value == 'block') { //if in block mode, blocks element. if (whattoblock != '' && whattoblock.match(/^\d{1,3}s/)) { //blocks single element showasblocked_unblocked(optionelement[optionelement.selectedindex], 'x', false, '1'); forpage = forpage.replace(whattoblock, ''); if(!unblockonly)createcookie('no', forpage, ((forsite == '' && forpage == '') ? -1: 365)); } else if (whattoblock == '') { //blocks elements. erasecookie('no' + activeselect()); ( var = optionelement.length - 1; >= 0, x = optionelement[i]; i--) { showasblocked_unblocked(x, 'x',false,'2'); } } else { if (!whatservertounblock) { // blocks server only. ( var = optionelement.length - 1; >= 0, x = optionelement[i]; i--) { if (whattoblock.indexof(x.title) != -1) { showasblocked_unblocked(x, 'x',false,'2'); } } forsite = forsite.replace(whattoblock, ''); if(!unblockonly)createcookie('no', forsite, ((forsite == '' && forpage == '') ? -1: 365), null, 'g'); } else { //blocks server resources available. var elemlist = ['ujs42-_noimgselect', 'ujs42-_noembedselect', 'ujs42-_noiframeselect', 'ujs42-_noscriptselect']; (var elemlistx = elemlist.length - 1; elemlistx >= 0, elemlisth = elemlist[elemlistx]; elemlistx--) { if (!document.getelementbyid(elemlisth)) { continue; } else { optionelement = document.getelementbyid(elemlisth); } ( var = optionelement.length - 1; >= 0, x = optionelement[i]; i--) { if (whattoblock.indexof(x.title) != -1) { showasblocked_unblocked(x, 'x', false, '2'); } } } forserverunblock = forserverunblock.replace(whattoblock, ''); if(!unblockonly)createcookie('noresource', forserverunblock, (forserverunblock == '' ? -1: 365), null, 'g'); } } } else { if (whattoblock != '' && whattoblock.match(/^\d{1,3}s/)) { //unblocks single element showasblocked_unblocked(optionelement[optionelement.selectedindex], false, false, '1'); if(!unblockonly)createcookie('no', whattoblock, 365, forpage); } else if (whattoblock == '') { //unblocks elements. var rt = []; ( var = optionelement.length - 1; >= 0, g = optionelement[i]; i--) { var z = + 's'; if (forpage.indexof(z) == -1) { showasblocked_unblocked(g,false,false,'2'); rt[rt.length] = z; } } if(!unblockonly)createcookie('no', rt.tostring().replace(/\,/g, ' '), 365, forpage); } else { if (!whatservertounblock) { //unblocks server only. ( var = optionelement.length - 1; >= 0, x = optionelement[i]; i--) { if (whattoblock.indexof(x.title) != -1) { showasblocked_unblocked(x,false,false,'2'); } } if(!unblockonly)createcookie('no', whattoblock, 365, forsite, 'g'); } else { //unblocks server resources available. var elemlist = ['ujs42-_noimgselect', 'ujs42-_noembedselect', 'ujs42-_noiframeselect', 'ujs42-_noscriptselect']; (var elemlistx = elemlist.length - 1; elemlistx >= 0, elemlisth = elemlist[elemlistx]; elemlistx--) { if (!document.getelementbyid(elemlisth)) { continue; } else { optionelement = document.getelementbyid(elemlisth); } ( var = optionelement.length - 1; >= 0, x = optionelement[i]; i--) { if (whattoblock.indexof(x.title) != -1) { showasblocked_unblocked(x, false, false, '2'); } } } if(!unblockonly)createcookie('noresource', whattoblock, 365, forserverunblock, 'g'); } } } blocktoggle(); } function blocktoggle() { //toggles block button unblock , vice versa. var = document.getelementbyid('ujs42-_nelbb'); var b = document.getelementbyid('ujs42-_no' + activeselect() + 'select'); if (b[b.selectedindex].innertext.indexof('#x# -') == 0) { a.value = 'unblock'; } else { a.value = 'block'; } } var scriptcount = 0; var scripturls = []; midori.addeventlistener('beforeexternalscript', function(e) { if (e.element.tagname != 'script') { //not script? nothing else return } var scriptsource = e.element.src; var forpage = readcookie('noscript'); var forsite = readcookie('noscript', 'g'); var forserverunblock = readcookie('noresource', 'g'); var link = document.createelement('a'); //same way hostname without needing match link.href = scriptsource; var linkhost = link.hostname; scriptnumber = scriptcount + 's'; //unique identifier script order in document. var scriptoption = document.createelement('option'); scriptoption.value = scriptnumber; scriptoption.innertext = scriptsource; scriptoption.setattribute('title', linkhost); if (!blocksiteresources && linkhost.indexof(location.hostname) != -1) { //do nothing if blocksiteresources off. } else if ((forpage && forpage.indexof(scriptnumber.tostring()) != -1) || (forsite && forsite.indexof(linkhost) != -1) || (forserverunblock && forserverunblock.indexof(linkhost) != -1)) { //if cookie contains , "unblocks" make sure added. scripturls.push(scriptoption); } else { //block scripts if cookie tells them not blocked. e.preventdefault(); scripturls.push(showasblocked_unblocked(scriptoption, 'x', 'h')); } scriptcount++; }, false); document.addeventlistener('domcontentloaded', function() { var userinterface = document.createelement('ujs42-_noresource'); userinterface.style = 'position:fixed;' + (cornerposition < 3 ? 'top': 'bottom') + ':1px;' + (cornerposition % 2 == 1 ? 'left': 'right') + ':1px;width:20px;height:20px;background:-o-skin("browser window skin");white-space:nowrap;z-index:9999;direction:ltr;border:1px solid black;'; userinterface.id = 'ujs42-_noresourceinterface'; //the interface unblocking resources , blocking them var uibackground = document.createelement('ujs42-_noresourceui'); //holds of ui elements, , centers them whenever possible uibackground.id = 'ujs42-_noiframeui'; uibackground.style.display = 'none'; uibackground.style.textalign = 'center'; var elementselection = document.createelement('select'); //to select list of elements block. elementselection.id = "ujs42-_noelementselect"; elementselection.onchange = showelementlist; elementselection.style.width = 'auto !important'; elementselection.style.marginleft = '20px !important'; uibackground.appendchild(elementselection); var noscriptlist = document.createelement('select'); //for listing scripts in page, needed blocked noscriptlist.onchange = blocktoggle; noscriptlist.id = "ujs42-_noscriptselect"; noscriptlist.style = 'width:300px;margin-right:20px !important;'; if (scripturls.length) { //start add scripts. var scriptscounter = document.createelement('option'); scriptscounter.innertext = 'scripts' + '(' + scripturls.length + ',' + scriptcount + ')'; //adds scripts counter blocked/unblocked, plus total number. scriptscounter.value = 'script'; elementselection.appendchild(scriptscounter); ( var = scripturls.length - 1; > -1; i--) { noscriptlist.appendchild(scripturls[i]); } uibackground.appendchild(noscriptlist); } //no scripts here? don't add. if(imgblockit){var x=generatelist('img'); if(x){elementselection.appendchild(x[0]);uibackground.appendchild(x[1]);}}//to add other resource lists, if wished. if(iframeblockit){var x=generatelist('iframe'); if(x){elementselection.appendchild(x[0]);uibackground.appendchild(x[1]);}} if(mediablockit){var x=generatelist('embed'); if(x){elementselection.appendchild(x[0]);uibackground.appendchild(x[1]);}} if (elementselection.innerhtml != '') { //no point carrying on if there aren't resources unblocked. var unblockselected = document.createelement('input'); unblockselected.type = 'button'; unblockselected.id = 'ujs42-_nelbb'; unblockselected.value = 'block'; //button block individual resources. unblockselected.onclick = block_unblock; uibackground.appendchild(unblockselected); var unblockall = document.createelement('input'); unblockall.type = 'button'; unblockall.value = 'all'; //button block resources. unblockall.onclick = block_unblock; uibackground.appendchild(unblockall); var tempunblock = document.createelement('input'); tempunblock.type = 'button'; tempunblock.value = 't-unblock'; //unblocks tab only. tempunblock.title = 'temporarily unblocks resources tab,warning: page reload, shift click webpage only. turn resource blocking on, either remove #nsoff url , hit enter or close tab , re-open it.'; tempunblock.onclick = function(e) { if (e.shiftkey) location.hash = '#nsoff'; else window.name = window.name + '#nsoff'; history.go(0); }; uibackground.appendchild(tempunblock); var unblockserver = document.createelement('input'); unblockserver.type = 'button'; unblockserver.id = 'ujs42-_nelser'; unblockserver.value = 'server'; //unblocks according server address. unblockserver.onclick = block_unblock; uibackground.appendchild(unblockserver); var previewresource = document.createelement('input'); previewresource.type = 'button'; previewresource.id = 'ujs42-_resourcepreview' previewresource.value = 'preview'; //previews resource in new tab. previewresource.onclick = function() { var selectedelementindex = document.getelementbyid('ujs42-_no' + activeselect() + 'select').selectedindex; var elementoption = document.getelementbyid('ujs42-_no' + activeselect() + 'select')[selectedelementindex].innertext; if (elementoption.indexof('#x# -') == 0) { window.open(elementoption.substr(5)) } else window.open(elementoption) }; uibackground.appendchild(previewresource); var showui = document.createelement('input'); showui.type = 'button'; showui.style = 'width:20px;height:20px;background:-o-skin("panel links");display:inline-block;position:absolute;' + (cornerposition < 3 ? 'top': 'bottom') + ':0px;' + (cornerposition % 2 == 1 ? 'left': 'right') + ':0px;'; //button on show interface. showui.onclick = function() { if (uibackground.style.display == 'none') { uibackground.style.display = 'inline-block'; userinterface.style.width = 'auto'; userinterface.style.height = 'auto'; if (document.getelementbyid('ujs42-_no' + activeselect() + 'select').disabled == false) { blocktoggle(); } } else { uibackground.style.display = 'none'; userinterface.style.width = '20px'; userinterface.style.height = '20px'; } } userinterface.appendchild(uibackground); userinterface.appendchild(showui); document.documentelement.appendchild(userinterface); var linebreak = document.createelement('br'); uibackground.insertbefore(linebreak, unblockselected); if (!document.getelementbyid('ujs42-_noscriptselect')) { elementselection.onchange(); } var stylesheet = document.createelement('style'); stylesheet.innertext = '#ujs42-_noresourceinterface *{font-family:sans-serif !important}#ujs42-_noresourceinterface input[type=button],#ujs42-_noresourceinterface select{border:2px outset black !important;margin:0px !important;}#ujs42-_noresourceinterface input[type=button]:active{outline:2px inset black !important;border:0px !important;}#ujs42-_noiframeui input[type=button]{background-color:#e0e0e0 !important;margin-right:4px !important}#ujs42-_noresourceinterface select{background-color:white !important;}@media screen , (max-width: 1200px) {#ujs42-_noiframeui *{font-size:10pt !important;}#ujs42-_noscriptselect,#ujs42-_noimgselect,#ujs42-_noiframeselect,#ujs42-_noembedselect{width:300px !important}}@media screen , (max-width: 800px) {#ujs42-_noiframeui *{font-size:8pt !important;}#ujs42-_noscriptselect,#ujs42-_noimgselect,#ujs42-_noiframeselect,#ujs42-_noembedselect{width:200px !important}} @media screen , (max-width: 500px) {#ujs42-_noiframeui *{font-size:6pt !important;}#ujs42-_noscriptselect,#ujs42-_noimgselect,#ujs42-_noiframeselect,#ujs42-_noembedselect{width:150px !important} #ujs42-_noiframeui input[type=button]{margin-right:0px !important}#ujs42-_resourcepreview,#ujs42-_nelbb{padding-left:0px !important;padding-right:0px !important}}@media screen , (max-width: 270px){#ujs42-_noiframeui{display:inline-block;}#ujs42-_noresourceinterface{width:100% !important;height:auto !important;content:"blockit can\'t viewed @ width";white-space:normal !important;text-align:center;}}'; //interesting bit here, script work or screen sizes, checks width , resizes accordingly, while keeping main toggle button out of way document.documentelement.appendchild(stylesheet); }}, false); } }) ()
documentation on midori sparse @ best , have no experience debugging javascript. know script nothing @ in midori.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Trying to force and Opera userjs to work in Midori...
Ubuntu
Comments
Post a Comment