// ==UserScript== // @name 学園祭カレンダー絞り込み // @description s:絞り込み // @version 0.1 // @run-at document-idle // @match *://www.gakkou.net/daigaku/gakuensai/* // @match *://todo-ran.com/t/soukan/* // @match *://todo-ran.com/t/kiji/* // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @require https://code.jquery.com/jquery-3.4.1.min.js // @namespace https://greasyfork.org/users/181558 // @downloadURL none // ==/UserScript== (function() { const SITEINFO = [{ url: "://www.gakkou.net/daigaku/gakuensai/", place: "H2.GESTitle", mapplace: "h3.ListTtlN", item: "ol[class^='articleListN']>li", parentGen: 0, defaultWord: "東京", ani: 500 }, { url: "://todo-ran.com/t/soukan/", place: "div.kiji_ktext", mapplace: "", item: "table#t_soukan_r tbody tr td a,table#t_soukan tbody tr td a", parentGen: 2, defaultWord: "消費", ani: null }]; if (location.href.match(/:\/\/todo-ran\.com\/t\/kiji\//)) { $("div.kiji>div:eq(2)").after($("a:contains('全相関記事を見る'):first").clone().css("float", "right")); } // ? if (location.href.match(/:\/\/todo-ran\.com\/t\/soukan\//)) $("table#t_soukan_r tbody tr td a,table#t_soukan tbody tr td a").each(function() { $(this).append("全相関記事を見る") }); var thissite = null; for (var i = 0; i < SITEINFO.length; i++) { if (SITEINFO[i].url == "") continue; if (location.href.match(SITEINFO[i].url)) thissite = i; } if (thissite === null) return; var defaultWord = SITEINFO[thissite].defaultWord || ""; if ($(SITEINFO[thissite].mapplace)) $(SITEINFO[thissite].mapplace).each(function() { $(this).append("[地図]"); }); $(SITEINFO[thissite].place).after('絞り込み(s) '); // autofocus="on" $("#sear").change(() => { shibo() }); document.addEventListener('keydown', function(e) { if (/input|textarea/i.test(e.target.tagName) == false) { var key = (e.shiftKey ? "Shift+" : "") + (e.altKey ? "Alt+" : "") + (e.ctrlKey ? "Ctrl+" : "") + e.key; if (key == "s") shibo(pref("defWord", prompt("絞り込みキーワード(正規表現)\n\n例:\n" + defaultWord + "\n\n", pref("defWord") || ""))); } }, false); function shibo(sear = null) { if (sear === null) sear = pref("defWord", $("#sear").val()); else $("#sear").val(pref("defWord", sear)); $(SITEINFO[thissite].item).each(function() { var ele = $(this); for (let i = 0; i < SITEINFO[thissite].parentGen; i++) { ele = ele.parent(); } if (!(ele.text().replace(/\r|\n|\s/gm, " ").match(new RegExp(sear.replace(/|/gm, "|").replace(/\s| /gm, ".*"), "gmi")))) { ele.hide(SITEINFO[thissite].ani); } else ele.show(SITEINFO[thissite].ani); }); } function pref(name, store = undefined) { // pref(name,data)で書き込み(数値でも文字列でも配列でもオブジェクトでも可)、pref(name)で読み出し var domain = (location.href.match(/^https?:\/{2,}(.*?)(?:\/|\?|#|$)/)[1] || location.href); if (store === undefined) { // 読み出し let data = GM_getValue(domain + " ::: " + name) if (data == undefined) return store; // 値がないなら終わり if (data.substr(0, 1) === "[") { // 配列なのでJSONで返す try { return JSON.parse(data || '[]'); } catch (e) { console.log("データベースがバグってるのでクリアします\n" + e); pref(name, []); return; } } else return data; } if (store === "" || store === [] || store === null) { // 書き込み、削除 GM_deleteValue(domain + " ::: " + name); return store; } else if (typeof store === "string") { // 書き込み、文字列 GM_setValue(domain + " ::: " + name, store); return store; } else { // 書き込み、配列 try { GM_setValue(domain + " ::: " + name, JSON.stringify(store)); } catch (e) { console.log("データベースがバグってるのでクリアします\n" + e); pref(name, ""); } return store; } } })()