| 4972 | } |
| 4973 | |
| 4974 | class RuleParser { |
| 4975 | constructor() { |
| 4976 | this.hpRules = []; |
| 4977 | this.smartRules = []; |
| 4978 | this.customRules = []; |
| 4979 | this.rules = []; |
| 4980 | this.pageDoc = document; |
| 4981 | this.nextLinkHref = null; |
| 4982 | this.nextTitle = ""; |
| 4983 | this.oldUrl = ""; |
| 4984 | this.curUrl = location.href; |
| 4985 | this.curSiteRule = {}; |
| 4986 | } |
| 4987 | |
| 4988 | async initSavedRules(callback) { |
| 4989 | var self = this; |
| 4990 | let smartRules = await getData("smartRules"); |
| 4991 | if (smartRules) self.smartRules = smartRules; |
| 4992 | let hpRules = await getData("hpRules"); |
| 4993 | if (hpRules) self.hpRules = hpRules; |
| 4994 | let customRules = await getData("customRules"); |
| 4995 | if (customRules) self.customRules = customRules; |
| 4996 | if (_unsafeWindow.pagetualRules && _unsafeWindow.pagetualRules.length) { |
| 4997 | _unsafeWindow.pagetualRules.forEach(rule => { |
| 4998 | rule.isScript = true; |
| 4999 | }); |
| 5000 | self.customRules = _unsafeWindow.pagetualRules.concat(self.customRules); |
| 5001 | } |
| 5002 | let rules = await getData("rules"); |
| 5003 | if (rules) self.rules = rules; |
| 5004 | callback(); |
| 5005 | } |
| 5006 | |
| 5007 | saveCurSiteRule() { |
| 5008 | /*if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.smart || this.curSiteRule.url.length<13)return; |
| 5009 | this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url}); |
| 5010 | this.hpRules.unshift(this.curSiteRule); |
| 5011 | if(this.hpRules.length>30){ |
| 5012 | this.hpRules.pop(); |
| 5013 | } |
| 5014 | storage.setItem("hpRules", this.hpRules);*/ |
| 5015 | } |
| 5016 | |
| 5017 | requestJSON(url, callback) { |
| 5018 | _GM_xmlhttpRequest({ |
| 5019 | url: url, |
| 5020 | method: 'GET', |
| 5021 | timeout: 1000000, |
| 5022 | headers: { |
| 5023 | 'accept': 'application/json,text/html', |
| 5024 | 'Referer': url |
| 5025 | }, |
| 5026 | onload: function(res) { |
| 5027 | let json = null; |
| 5028 | try { |
| 5029 | json = JSON.parse(res.response || res.responseText); |
| 5030 | } catch(e) { |
| 5031 | debug(e, 'Error json'); |
nothing calls this directly
no outgoing calls
no test coverage detected