-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter.min.js
6 lines (6 loc) · 2.91 KB
/
filter.min.js
1
2
3
4
5
6
var filterObj=function(){var f,d=[],k,l=30,h=[],e,m=function(a){for(var b=document.getElementsByClassName("alert"),c=b.length,e=d.length,i=!1,f="",g=0;g<c;g++){for(var i=!1,f=b[g],h=0;h<e;h++)if(d[h]==f){i=!0;break}i||d.push(b[g])}a&&a()},p=function(){var a=document.createElement("span"),b=document.createElement("img");b.src=chrome.extension.getURL("assets/close.png");a.className="closeBtn";b.addEventListener("click",function(){document.getElementById("filterDiv").style.display="none"});a.appendChild(b);
f.appendChild(a)},j=function(a,b,c,e,f,d){var a=document.createElement(a),g;a.id=b||"";a.name=c||"";a.value=e||"";a.className=d||"";for(g in f)f.hasOwnProperty(g)&&(a[g]=f[g]);return a},q=function(a){a.addEventListener("change",function(){var b=d.length,c;if(a.checked===!0)for(c=0;c<b;c++){if(RegExp("(^| )"+a.value+"( |$)").test(d[c].className))d[c].style.display="none",--l}else for(c=0;c<b;c++)if(RegExp("(^| )"+a.value+"( |$)").test(d[c].className))d[c].style.display="inherit",++l;b=a.value;c=a.checked;
for(f in e)if(e[f].id===b){e[f].checked=c;break}localStorage.filters=JSON.stringify(e)})},n=function(){k=document.getElementsByClassName("ajax_paginate")[0].firstChild;r()},r=function(){k.addEventListener("click",function(){var a=0,b=window.setInterval(function(){a++;m(o);a===20&&(n(),window.clearInterval(b))},200)})},o=function(){for(var a=h.length,b=0;b<a;b++)if(h[b].checked===!0){var c=document.createEvent("HTMLEvents");c.initEvent("change",!1,!0);h[b].dispatchEvent(c)}},s=function(){var a=!1,
b=new XMLHttpRequest;b.onreadystatechange=function(){b.readyState==4&&(a=JSON.parse(b.responseText))};b.open("GET",chrome.extension.getURL("/manifest.json"),!1);try{b.send()}catch(c){}return a}();return{init:function(){var a=localStorage.githubNewsFilterVersion,b=s.version;if(!a||a!==b)localStorage.removeItem("filters"),localStorage.githubNewsFilterVersion=b;localStorage.filters?e=JSON.parse(localStorage.filters):(e={issueComment:{text:"Issue Comment",id:"issues_comment",checked:!1},commitComment:{text:"Commit Comment",
id:"commit_comment",checked:!1},pullRequest:{text:"Pull Request & Issue Opened",id:"issues_opened",checked:!1},follow:{text:"Follow",id:"follow",checked:!1},gist:{text:"Gist",id:"gist",checked:!1},push:{text:"Push",id:"push",checked:!1},created:{text:"Created Branch",id:"create",checked:!1},issueClosed:{text:"Close & Merge",id:"issues_closed",checked:!1},fork:{text:"Forked",id:"fork",checked:!1},watch:{text:"Watch",id:"watch_started",checked:!1},editWiki:{text:"Wiki",id:"gollum",checked:!1}},localStorage.filters=
JSON.stringify(e));a=document.createElement("div");a.id="filterDiv";a.className="filterBar";document.getElementById("footer").appendChild(a);f=a;p();m();for(var c in e){a=j("input",c,c,e[c].id,{type:"checkbox"});q(a);if(e[c].checked)a.checked=!0;b=j("label");b.innerHTML=e[c].text;var d=j("span");d.className="filterOption";d.appendChild(b);d.appendChild(a);h.push(a);f.appendChild(d)}n();o()}}}();filterObj.init();