// ==UserScript== // @id Change_search_result_for_Google_and_Bing@noi // @name Change search result for Google and Bing // @version 2.02 // @copyright Noi & Noisys & NoiSystem & NoiProject // @license https://creativecommons.org/licenses/by-nc-sa/3.0/ // @author noi // @description change or hide search results of Google & Bing // @include *.google.* // @include *www.bing.com/* // @namespace https://greasyfork.org/scripts/2229 // @homepageURL https://greasyfork.org/scripts/2229 // @run-at document-end // @grant GM_log // @grant GM_config // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_registerMenuCommand // @downloadURL https://update.greasyfork.icu/scripts/2229/Change%20search%20result%20for%20Google%20and%20Bing.user.js // @updateURL https://update.greasyfork.icu/scripts/2229/Change%20search%20result%20for%20Google%20and%20Bing.meta.js // ==/UserScript== /*************************************************************************************** //require GreaseMonkey Script Configurator 1.2.57 // //Copyright: JoeSimmons & Sizzlemctwizzle & IzzySoft // //(c)https://greasyfork.org/scripts/1884-gm-config // //license LGPL version 3 or any later version; http://www.gnu.org/copyleft/lgpl.html // ***************************************************************************************/ /*===================================================================================================================== ************************************************************************* ***注意:文字コードはUFT-8で保存してくださいNotice for 2byte Charactor *** ************************************************************************* ===解説(Read me)=== ・GoogleとBingの検索結果を非表示にする機能(Hide the search result by google or Bing) ・GoogleとBingの検索結果のURLを変更する機能(Change the search result's URL by google or Bing) [非表示について(about to hide)]----------------------------------------------------------------------------- ===例文For example=== ex)"hogehoge"と"wiki"が両方共あって、"jp"か"com"のどちらともなかったら検索結果を消す (Hit "hogehoge" and "wiki" ,And still "jp" or "com" are not included.Hide result) { NGword : ["hogehoge","wiki"], ignore : ["jp","com"]}, ===ヒント(hint)=== ・項目は複数指定が可能(Items can be increased) ・NGwordはand条件です("NGword" is AND condition) ・ignoreはor条件です("ignore" is OR condition) ・""のように文字を指定しない場合は無視されます("" is ignored) ・日本語で検索できるので嫌いな単語が含まれたら消すことが出来ます。 (Can search for Japanese) [URL置換について(about to change URL)]---------------------------------------------------------------------- ===例文For example=== ex)"www.hogehoge.com"を"hogehoge.com"にする (Change "www.hogehoge.com" to "hogehoge.com") { before : "www.hogehoge.com", after : "hogehoge.com" }, ex)"hogehoge"を消す (Delete "hogehoge") { before : "hogehoge", after : "" }, ex)"ぬるぽ"を"ガッ"にする (Change "ぬるぽ" to "ガッ". for 2byte charactor.) { before : "ぬるぽ", after : "ガッ" }, ===ヒント(hint)=== ・項目は1つだけなので増やせません(Only one item. Can not be added) ・beforeは検索用のURLです("before" is search URL) ・afterは変換後のURLです("after" is changed URL) ・beforeで""のように文字を指定しない場合は無視されます("" is ignored in before) ・どちらも日本語で指定するとURL表記に変更されます。※パーセントエンコードします (2byte charactor is changed to the URL notation.for Japanese) ・もし検索条件を追加したいなら(If you would like to add a search condition.) ex:add ie=utf-8 @Google("http://www.google.com/search?num=50" to "http://www.google.com/search?ie=utf-8&num=50") { before : "search?", after : "search?ie=utf-8&" }, ===注意事項(notice)=== ************************************************************************* 一番最後のカンマ(,)を忘れないこと(Do not forget the last comma) ・同じ単語を指定すると干渉する場合があります (If you specify the same word,May interfere) ************************************************************************* =====================================================================================================================*/ /************************************************************************************************************* 更新履歴 11/30/2017 - v2.02 fix : 仕様変更対応 03/31/2015 - v2.01 fix : 重複していた処理の修正 02/11/2015 - v2.00 add : Simple format check 02/11/2015 - v2.00 add : bing 08/19/2014 - v1.15 add : close config when keydown ESC 08/19/2014 - v1.15 fix : config button 06/13/2014 - v1.14 del : @updateURL 06/12/2014 - v1.13 add : @grant & @homepageURL 06/07/2014 - v1.12 update : delete require. and include the code in script. 06/05/2014 - v1.11 fix : userscripts.org 05/17/2014 - v1.10 fix : userscripts.org:8080 03/14/2014 - v1.9 fix : Fixed [undefined] Error (GoogleSearchButton) 06/11/2013 - v1.8 fix : Fixed for Chrome 06/10/2013 - v1.7 fix : Fixed that did not work When logout 06/09/2013 - v1.6 fix : It corresponded to specification change of google. 04/06/2013 - v1.5 fix : The fault which will not operate if logged in to Google was corrected. 03/19/2013 - v1.4 update : For AutoPager & AutoPagerize. 03/09/2013 - v1.3 fix : Config window For Chrome 03/09/2013 - v1.2 add : GM_config 01/29/2013 - v1.1 add : check update 11/13/2011 - v1.0 release **************************************************************************************************************/ /************************************************************************************************************* 備忘録 ・以下をgreasyforkに変更 http://www.userscripts.org/scripts/show/117908 http://userscripts.org/scripts/source/117908.user.js ・@updateURLを削除(インストールしたときのサイトURLをアドオンが保持しているので更新可能な模様) **************************************************************************************************************/ //==================================================================================================================== (function(){ if(window!=parent)return; //iframeは除外 if(location.host.match("plus.google.com")) return; var hideList = ""; var changeList = ""; //ユーザーコンフィグ画面(GM_config) userCfg(); //メイン handle(document); //プログラム部Main PG================================================================================================== //非表示処理(Hide result)-------------------------------------------------------------------------- function handle(node){ if(!node.tagName && node != document) return if(hideList == ""){ alert("format error : hideList"); return;} if(changeList == ""){ alert("format error : changeList"); return;} var result_Hide = document.getElementsByTagName('li'); if(node.tagName && node.tagName.match(/^li$/i)) result_Hide = [node]; for (i = 0; i < result_Hide.length; i++){ var strTag = result_Hide[i]; //検索結果のテキスト情報(Search result) var hideFlg = 0; //非表示フラグ(Hide flag) //0:初期値(initial) 1:非表示(hide) 2:表示(visible) for (j = 0; j < hideList.length; j++){ //非表示処理(Hide result)-------------------------------------------------- for (k = 0; k < hideList[j].NGword.length; k++){ if (hideList[j].NGword[k] == "" ){ continue; } if (strTag.className.match(/(g|gb_algo)/i) && strTag.innerHTML.match(hideList[j].NGword[k])){ hideFlg = 1; }else{ hideFlg = 2; } } //例外判定(Exception)------------------------------------------------------ for (k = 0; k < hideList[j].ignore.length; k++){ if (hideList[j].ignore[k] == "" ){ continue; } if (strTag.className.match(/(g|gb_algo)/i) && strTag.innerHTML.match(hideList[j].ignore[k])){ hideFlg = 2; //throw "test";//変数確認用 } } //検索結果削除(Delete result)---------------------------------------------- if (hideFlg == 1){ strTag.innerHTML = ''; hideFlg = 0; strTag.setAttribute('style', 'display:none;'); } } } //URL置換Change URL---------------------------------------------------------------------------------------- var result_Ch = document.evaluate('.//H3', node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) //google if(!result_Ch.snapshotLength)result_Ch = document.evaluate('.//H2', node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); //bing for (i = 0; i < result_Ch.snapshotLength; i++){ for(j = 0; j < result_Ch.snapshotItem(i).getElementsByTagName('a').length; j++){ var oldLink = result_Ch.snapshotItem(i).getElementsByTagName('a')[j].getAttribute('href'); //検索結果のURL(Original URL) for (k = 0; k < changeList.length; k++){ if (changeList[k].before == ""){ continue; } var newLink = oldLink.replace(encStr(changeList[k].before), encStr(changeList[k].after)); //置換後のリンク(Changed URL) if (newLink != oldLink){ result_Ch.snapshotItem(i).getElementsByTagName('a')[j].setAttribute('href', newLink); } } } } } //共通プログラムCommon PG======================================================================================= //日本語をパーセントエンコードする(For Japanese encode)------------------------------------- function encStr( str ){ var encodeString = encodeURI(str) ; return encodeString; } //ユーザー設定画面(userconfig)------------------------------------------------------------- function userCfg(){ //============================================================== //GreaseForkがrequireの審査必要なのでいっそのこと埋め込みました。 //Copyright: JoeSimmons & Sizzlemctwizzle & IzzySoft //require (c)https://greasyfork.org/scripts/1884-gm-config //============================================================== //============================引用開始=================================== var GM_config = { storage: 'GM_config', init: function(){ for(var i=0,l=arguments.length,arg; i0) for(var i=radios.length-1; i>=0; i--) { if(radios[i].checked) GM_config.values[f] = radios[i].value; } break; } }, doSettingValue : function(settings, stored, i, oldi, k) { var set = k!=null && k==true && oldi!=null ? settings[oldi]["kids"][i] : settings[i]; if(",save,open,close".indexOf(","+i) == -1) { // The code below translates to: // if a setting was passed to init but wasn't stored then // if a default value wasn't passed through init() then use null // else use the default value passed through init() // else use the stored value try { var value = (stored[i]==undefined ? (set["default"]==undefined ? null : set["default"]) : stored[i]); } catch(e) { var value = (stored[i]=="undefined" ? (set["default"]=="undefined" ? null : set["default"]) : stored[i]); } // If the value isn't stored and no default was passed through init() // try to predict a default value based on the type if (value === null) { switch(set["type"]) { case 'radio': case 'select': value = set.options[0]; break; case 'checkbox': value = false; break; case 'int': case 'float': value = 0; break; default: value = (typeof stored[i]=="function") ? stored[i] : ""; } } } GM_config.passed_values[i] = value; }, doReset : function(field, type, oldf, f, k) { var isKid = k!=null && k==true, obj=GM_config, set = isKid ? obj.settings[oldf]["kids"][f] : obj.settings[f]; switch(type) { case 'text': field.value = set['default'] || ''; break; case 'hidden': case 'password': field.value = set['default'] || ''; break; case 'textarea': field.value = set['default'] || ''; break; case 'checkbox': field.checked = set['default'] || false; break; case 'select': if(set['default']) { for(var i=field.options.length-1; i>=0; i--) if(field.options[i].value==set['default']) field.selectedIndex=i; } else field.selectedIndex=0; break; case 'span': var radios = field.getElementsByTagName('input'); if(radios.length>0) for(var i=radios.length-1; i>=0; i--) { if(radios[i].value==set['default']) { radios[i].checked=true; } } break; } }, values: {}, settings: {}, css: { basic: 'body {background:#FFFFFF;}\n' + '.indent40 {margin-left:40%;}\n' + '* {font-family: arial, tahoma, sans-serif, myriad pro;}\n' + '.field_label {font-weight:bold; font-size:12px; margin-right:6px;}\n' + '.block {display:block;}\n' + '.saveclose_buttons {\n' + 'margin:16px 10px 10px 10px;\n' + 'padding:2px 12px 2px 12px;\n' + '}\n' + '.reset, #buttons_holder, .reset a {text-align:right; color:#000000;}\n' + '.config_header {font-size:20pt; margin:0;}\n' + '.config_desc, .section_desc, .reset {font-size:9pt;}\n' + '.center {text-align:center;}\n' + '.section_header_holder {margin-top:8px;}\n' + '.config_var {margin:0 0 4px 0; display:block;}\n' + '.config_var {font-size: 13px !important;}\n' + '.section_header {font-size:13pt; background:#414141; color:#FFFFFF; border:1px solid #000000; margin:0;}\n' + '.section_desc {font-size:9pt; background:#EFEFEF; color:#575757; border:1px solid #CCCCCC; margin:0 0 6px 0;}\n' + 'input[type="radio"] {margin-right:8px;}', stylish: '' }, create: function(a,b) { var ret=window.document.createElement(a); if(b) for(var prop in b) { if(prop.indexOf('on')==0) ret.addEventListener(prop.substring(2),b[prop],false); else if(prop=="kids" && (prop=b[prop])) for(var i=0; i'); //設定ボタンクリックで設定画面を呼び出す(Open Config Window,when click the Config Button) var setBtn = document.getElementById("setBtn"); setBtn.addEventListener('click', function(){GM_config.open()}, true); }else{ GM_log("CSR_Error:検索Buttonが見つからない") } //設定画面(Config Window) GM_config.init('Config - Change search result for Google' /* Script title */, /* Settings object */ { 'hideList': // This would be accessed using GM_config.get('Name') { 'section': ['hideList'], 'label': '{ NGword : ["word1","word2","word3","word...more"], ignore : ["word4","word5","word...more"] },', // Appears next to field 'type': 'textarea', // Makes this setting a text field cols: 120, rows: 10, 'default': '{ NGword : ["","","",""], ignore : ["",""] },\n' + '{ NGword : ["",""], ignore : ["","",""] },\n' + '{ NGword : [""], ignore : [""] },\n' + '{ NGword : ["","",""], ignore : ["",""] },\n' + '{ NGword : [""], ignore : ["","","","",""] },\n' // Default value if user doesn't change it }, 'changeList': // This would be accessed using GM_config.get('Name') { 'section': ['changeList'], 'label': '{ before : "beforeURL", after : "afterURL" },', // Appears next to field 'type': 'textarea', // Makes this setting a text field cols: 120, rows: 10, 'default': '{ before : "scribe.twitter.com", after : "twitter.com" }, //Twitterの表示されないURL(Delete scribe)\n' + '{ before : "zxbtapi.appspot.com", after : "twitter.com" }, //appspot回避(Avoid appspot)\n' + '{ before : "", after : "" },\n' + '{ before : "", after : "" },\n' + '{ before : "", after : "" },\n' // Default value if user doesn't change it } }, /* chrome非対応のため削除(Delete :this CSS do not work on Chrome)******************************************: '.section_header_holder{height:33%;width:80%;}' + //枠 '#section_1{padding-top:50px;}' + //changeListの枠 '.section_header.center{background:aliceblue!important;color:black;pointer-events: none;border:none;}' + //タイトル '#field_hideList{height:100%;width:100%;resize: none;}' + //hideListテキスト '#field_changeList{height:100%;width:100%;resize: none;}' + //changeListテキスト '#buttons_holder{width:20%;position:absolute;bottom:10%;right:10px;}', + //セーブ・キャンセル・リセットボタン ***************************************************************************************/ { open: function() { //config window var cfg_Window = document.getElementById("GM_config"); //リスト全部(list section)================================================= var cfg_hideSection = cfg_Window.contentDocument.getElementById("section_0"); //hideList var cfg_changeSection = cfg_Window.contentDocument.getElementById("section_1"); //changeList cfg_hideSection.setAttribute("style", "height:33%;width:80%;"); cfg_changeSection.setAttribute("style", "height:33%;width:80%;padding-top:50px;"); //section label============================================================ var cfg_hideLabel = cfg_Window.contentDocument.getElementById("c_section_kids_0"); //hideList var cfg_changeLabel = cfg_Window.contentDocument.getElementById("c_section_kids_1"); //changeList cfg_hideLabel.setAttribute("style", "background:aliceblue!important;color:black;pointer-events: none;border:none;"); cfg_changeLabel.setAttribute("style", "background:aliceblue!important;color:black;pointer-events: none;border:none;"); //textarea================================================================= var cfg_hideTxt = cfg_Window.contentDocument.getElementById("field_hideList"); //hideList var cfg_changeTxt = cfg_Window.contentDocument.getElementById("field_changeList"); //changeList //改行無効化 cfg_hideTxt.setAttribute("wrap", "off"); cfg_changeTxt.setAttribute("wrap", "off"); //css cfg_hideTxt.setAttribute("style", "height:100%;width:100%;resize: none;"); cfg_changeTxt.setAttribute("style", "height:100%;width:100%;resize: none;"); //save cancel============================================================== var cfg_buttonsHolder = cfg_Window.contentDocument.getElementById("buttons_holder"); cfg_buttonsHolder.setAttribute("style", "width:20%;position:absolute;bottom:10%;right:10px;"); var cfg_body = cfg_Window.contentDocument.getElementsByTagName("body")[0]; cfgClose(document); cfgClose(cfg_body); //ESC押したら設定画面閉じる function cfgClose(doc){ try{ doc.onkeydown = function(evt){ if (evt){ var kc = evt.keyCode; }else{ var kc = event.keyCode; } //GM_log(kc); if(kc!=27){ return; } GM_config.close(); } }catch(e){ GM_log("CSR_escClose:"+e); } }//cfgCloseここまで } }); var cssTxt = '#GM_config{height:100%!important;width:100%!important;z-index:1000!important;}'; addCSS(cssTxt); //GreaseMonkeyとScriptishのオプション追加(add Option) GM_registerMenuCommand("Config - Change search result for Google", GM_config.open); //変数取得(get variable) var hideListSaved = GM_config.get("hideList"); var changeListSaved = GM_config.get("changeList"); //alert(GM_config.get("hideList")); //alert(GM_config.get("changeList")); //最終カンマ削除(delete last comma) do{ hideListSaved = hideListSaved.slice(0, -1); //alert(hideListSaved.slice(-1)); }while(hideListSaved.slice(-1) != '}'); do{ changeListSaved = changeListSaved.slice(0, -1); //alert(changeListSaved.slice(-1)); }while(changeListSaved.slice(-1) != '}'); //alert(hideListSaved); //alert(changeListSaved); try{ //変数セット(set variable) hideList = eval("[" + hideListSaved + "]"); changeList = eval("[" + changeListSaved + "]"); }catch(e){ GM_log("CSR_変数error" +e); return; } /*********************** GM_config以前の設定 *************** //非表示リスト(Hide result LIST)-------------------------------------------------------------------- var hideList = [ { NGword : ["",""], ignore : ["",""]}, //以下に追加(Add Location start)********************************************************************** { NGword : ["","","",""], ignore : ["",""] }, //追加サンプル(sample) { NGword : [""], ignore : ["","",""] }, //追加サンプル(sample) { NGword : [""], ignore : [""] }, //追加サンプル(sample) { NGword : ["",""], ignore : ["",""] }, //追加サンプル(sample) { NGword : ["",""], ignore : ["",""] }, //追加サンプル(sample) //上に追加(Add Location end)************************************************************************** { NGword : ["",""], ignore : ["",""]} ]; //変換リスト(Change URL LIST)---------------------------------------------------------------------- var changeList = [ { before : "scribe.twitter.com", after : "twitter.com" }, //Twitterの表示されないURL(Delete scribe) //以下に追加(Add Location start)********************************************************************** { before : "zxbtapi.appspot.com", after : "twitter.com" }, //appspot回避(Avoid appspot) { before : "", after : "" }, //追加サンプル(sample) { before : "", after : "" }, //追加サンプル(sample) { before : "", after : "" }, //追加サンプル(sample) //上に追加(Add Location end)************************************************************************** { before : "", after : "" } //追加サンプル(sample) ]; //ユーザ設定から読み込み(Load user's settings) var hideListSaved = eval( GM_getValue("hideList")); var changeListSaved = eval( GM_getValue("changeList")); //ユーザー設定を保存(Save user's settings) if(hideList != hideListSaved){ GM_setValue( "hideList", hideList.toSource() ); } if(changeList != changeListSaved){ GM_setValue( "changeList", changeList.toSource() ); } ************************************************************/ } //For Chrome:Change "GM_setValue & GM_getValue" to WebStrage------------------------------------------- if (!this.GM_getValue) { this.GM_getValue=function (key,def) { return window.localStorage.getItem(key); }; this.GM_setValue=function (key,value) { return window.localStorage.setItem(key, value); }; } //css追加 function addCSS(css){ var head = document.getElementsByTagName('head'); if(!head) return; else head = head[0]; var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style); } //For AutoPagerize----------------------------------------------------------------------------------- document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){ var node = evt.target; handle(node); }, false); //For AutoPager-------------------------------------------------------------------------------------- document.body.addEventListener('AutoPagerAfterInsert', function(evt){ var node = evt.target; handle(node); }, false); //For AutoPatchWork---------------------------------------------------------------------------------- document.body.addEventListener('AutoPatchWork.DOMNodeInserted', function(evt){ var node = evt.target; handle(node); }, false); })(); //=====================================================================================================================