Changeset 9373
- Timestamp:
- 04/13/08 02:00:55 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/googlereaderfullfeed.user.js
r8886 r9373 29 29 AAAAACwAAAAAEwATAAAETBDISWsNOOuNJf+aB4LiyJUZ0awNsqGB0RSYkAwhoAnKYaIEBm4EXJgC 30 30 QGFA1VBmUDwfJjjs6DQy2tJp5TBX0uf1mCO/xmYk2mxptyMAOw== 31 ]]></>.toString().replace(/\s+/g, ""); 31 ]]></>.toString() 32 .replace(/\s+/g, ""); 32 33 const ICON2 = <><!-- (c) id:Constellation --><![CDATA[data:image/gif;base64, 33 34 R0lGODdhEwATAPQAMUFp4YfO64fO7ofW9Yfe+LHO68XW68X3/MX3/9ne6+zn7uz/+Oz//Oz////v … … 35 36 EwATAAAFUCAgjmRZBmiqrqjIvqoLw/LM1unQQLyz4gECJIESHAwxgEqAUNhwAwZyBl0UnsqcNKCD 36 37 PKatbLGpBQeAQiJ3mwJydzxn0vZy0+1Y+s3EN4UAADs= 37 ]]></>.toString().replace(/\s+/g, ""); 38 ]]></>.toString() 39 .replace(/\s+/g, ""); 38 40 39 41 // == [Config] ====================================================== … … 65 67 this.itemInfo.item_body = getFirstElementByXPath(bodyXPath); 66 68 this.state = 'wait'; 67 68 if (this.info.enc) { 69 this.mime = 'text/html; charset=' + this.info.enc; 70 } else { 71 this.mime = 'text/html; charset=' + document.characterSet; 72 } 73 69 this.mime = 'text/html; charset=' + (this.info.enc || document.characterSet); 74 70 75 71 this.request(); … … 90 86 }, 91 87 onerror: function() { 92 self.requestError.apply(self, ['Request Error']) 88 self.requestError.apply(self, ['Request Error']); 93 89 }, 94 90 onload: function(res) { 95 91 if (res.status == 302) { 96 92 try { 97 opt.url = res.responseHeaders.match(/\sLocation:\s+( [^\s]+)/)[1];93 opt.url = res.responseHeaders.match(/\sLocation:\s+(\S+)/)[1]; //i 98 94 window.setTimeout(GM_xmlhttpRequest, 0, opt); 99 95 return; … … 102 98 } 103 99 } 104 self.requestLoad.apply(self, [res]) 100 self.requestLoad.apply(self, [res]); 105 101 } 106 102 }; … … 119 115 text = text.replace(/(<[^>]+?[\s"'])on(?:(?:un)?load|(?:dbl)?click|mouse(?:down|up|over|move|out)|key(?:press|down|up)|focus|blur|submit|reset|select|change)\s*=\s*(?:"(?:\\"|[^"])*"?|'(\\'|[^'])*'?|[^\s>]+(?=[\s>]|<\w))(?=[^>]*?>|<\w|\s*$)/gi, 120 116 "$1"); 121 if (REMOVE_SCRIPT) text = text.replace(/<script [^>]*>[\S\s]*?<\/script\s*>/gi, "");122 if (REMOVE_H2TAG) text = text.replace(/<h2 [^>]*>[\S\s]*?<\/h2\s*>/gi, "");117 if (REMOVE_SCRIPT) text = text.replace(/<script(?:\s[^>]+?)?>[\S\s]*?<\/script\s*>/gi, ""); 118 if (REMOVE_H2TAG) text = text.replace(/<h2(?:\s[^>]+?)?>[\S\s]*?<\/h2\s*>/gi, ""); 123 119 var htmldoc = parseHTML(text); 124 120 removeXSSRisks(htmldoc); … … 128 124 relativeToAbsolutePath(htmldoc, this.itemInfo.itemURL); 129 125 } 130 for (var i = 0, l = FullFeed.documentFilters.length; i < l; 131 FullFeed.documentFilters[i++](htmldoc, this.itemInfo.itemURL, this.info)); 126 var self = this; 127 FullFeed.documentFilters.forEach(function(filter) { 128 filter(htmldoc, self.itemInfo.itemURL, this.info); 129 }); 132 130 try { 133 131 var entry = getElementsByXPath(this.info.xpath, htmldoc); … … 145 143 this.removeEntry(); 146 144 entry = this.addEntry(entry); 147 for (var i = 0, l = FullFeed.filters.length; i < l; 148 FullFeed.filters[i++](entry)); 145 FullFeed.filters.forEach(function(filter) { 146 filter(entry); 147 }); 149 148 this.requestEnd(); 150 149 } else { … … 189 188 190 189 FullFeed.parser = function(text) { 191 var lines = text.split(/ \r?\n|\r/);190 var lines = text.split(/[\r\n]+/); 192 191 var reg = /^([^:]+):(.*)$/; 193 192 var trimspace = function(str) { … … 195 194 }; 196 195 var info = {}; 197 for (var i = lines.length; i --> 0;) {198 if (reg.test(line s[i])) {196 lines.forEach(function(line) { 197 if (reg.test(line)) { 199 198 info[RegExp.$1] = trimspace(RegExp.$2); 200 199 } 201 } 200 }); 202 201 var isValid = function(info) { 203 202 var infoProp = ['url', 'xpath']; 204 for (var i = infoProp.length; i --> 0; ) { 205 if (!info[infoProp[i]]) { 206 return false; 207 } 208 } 203 if (infoProp.some(function(prop) { 204 return !info[prop]; 205 })) return false; 209 206 try { 210 207 new RegExp(info.url); … … 240 237 var info = []; 241 238 var doc = parseHTML(res.responseText); 242 var lists = getElementsByXPath(243 '//textarea[@class="ldrfullfeed_data"]', doc);239 var lists = 240 getElementsByXPath('//textarea[@class="ldrfullfeed_data"]', doc); 244 241 lists.forEach(function(list) { 245 242 var data = FullFeed.parser(list.value); … … 267 264 if (!WIDGET) return; 268 265 var exps = []; 269 for (var i = 0, l = SITE_INFO.length; i < l; exps.push(SITE_INFO[i++].url)); 270 for (var url in cacheInfo) { 271 var site = cacheInfo[url]; 272 for (var i = 0, l = site.info.length; i < l; exps.push(site.info[i++].url)); 266 SITE_INFO.forEach(function(info) { 267 exps.push(info.url); 268 }); 269 for each (var i in cacheInfo) { 270 i.info.forEach(function(info) { 271 exps.push(info.url); 272 }); 273 273 } 274 274 pattern = exps.join('|'); … … 393 393 this.item_container = getFirstElementByXPath('id("current-entry")//div[contains(concat(" ",normalize-space(@class)," ")," entry-body ")]'); 394 394 this.title = this.item.title; 395 this.f ind = false;395 this.found = false; 396 396 }; 397 397 398 398 var launchFullFeed = function(list, c) { 399 if ( !list) return;400 for (var i = 0, l = list.length; i < l; i++) {401 var reg = new RegExp( list[i].url);399 if (typeof list.some != "function") return; 400 list.some(function(i) { 401 var reg = new RegExp(i.url); 402 402 if (reg.test(c.itemURL) || reg.test(c.feedURL)) { 403 c.find = true; 404 var ff = new FullFeed(list[i], c); 405 break; 403 c.found = true; 404 var ff = new FullFeed(i, c); 405 return true; 406 } else { 407 return false; 406 408 } 407 } 409 }); 408 410 }; 409 411 … … 420 422 launchFullFeed(SITE_INFO, c); 421 423 422 if (!c.find) { 423 for (var i = 0, l = SITEINFO_IMPORT_URLS.length; i < l && !c.find; 424 launchFullFeed(cacheInfo[SITEINFO_IMPORT_URLS[i++]].info, c)); 425 } 426 427 if (!c.find) { 424 if (!c.found && !SITEINFO_IMPORT_URLS.some(function(url) { 425 launchFullFeed(cacheInfo[url].info, c); 426 return c.found; 427 })) { 428 428 message('This entry is not listed on SITE_INFO'); 429 429 if (OPEN) window.open(c.itemURL) || message('Cannot popup'); … … 477 477 478 478 function searchEntry(htmldoc) { 479 479 480 var xpath = [ 480 481 '//*', 481 '[(..//h2) or (.//h3) or (.//h4) or (.//h5) or (.//h6) or (..//*[contains(concat(@id,@class,""),"title")])]', 482 '[not(.//form)]', 483 '[not((.|.//*)[contains(concat("",@class,""),"robots-nocontent")])]', 484 '[not((.|.//*)[contains(concat(@id,@class,""),"side")])]', 485 '[not((.|.//*)[contains(concat(@id,@class,""),"navi")])]', 486 '[not((.|.//*)[contains(concat(@id,@class,""),"footer")])]', 487 '[not((.|.//*)[contains(concat(@id,@class,""),"header")])]', 482 '[(..//h2) or (.//h3) or (.//h4) or (.//h5) or (.//h6) or (..//*[contains(concat(@id, " ", @class), "title")])]', 483 '[not(.//form|ancestor-or-self::form)]', 484 '[not(.//script|ancestor-or-self::script)]', 485 '[not((.|.//*|ancestor-or-self::*)[contains(@class, "robots-nocontent")])]', 486 '[not((.|.//*|ancestor-or-self::*)[contains(concat(@id, " ", @class), "side")])]', 487 '[not((.|.//*|ancestor-or-self::*)[contains(concat(@id, " ", @class), "navi")])]', 488 '[not((.|.//*|ancestor-or-self::*)[contains(concat(@id, " ", @class), "footer")])]', 489 '[not((.|.//*|ancestor-or-self::*)[contains(concat(@id, " ", @class), "header")])]', 488 490 ].join(''); 489 491 try { … … 492 494 var elms = getElementsByXPath(xpath, htmldoc); 493 495 if(!elms) return null; 494 // get content which has most text elements.496 // get content which has most text elements. 495 497 Array.forEach(elms, function(e) { 496 var n = e.textContent.length; 498 if(typeof e.textContent != "string") return; 499 var n = e.textContent.replace(/^\s+|\s+$|(?:\r?\n|\r){2,}/g, "").length; 497 500 if(max < n){ 498 501 max = n; … … 619 622 var nodesSnapshot = (node.ownerDocument || node). 620 623 evaluate(xpath, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 621 var data = [] 624 var data = []; 622 625 for (var i = 0, l = nodesSnapshot.snapshotLength; i < l; 623 626 data.push(nodesSnapshot.snapshotItem(i++))); … … 634 637 // copied from Pagerization (c) id:ofk 635 638 function parseHTML(str) { 636 str = str.replace(/^[\s\S]*?<html [^>]*>|<\/html\s*>[\s\S]*$/ig, '');639 str = str.replace(/^[\s\S]*?<html(?:\s[^>]+?)?>|<\/html\s*>[\S\s]*$/ig, ''); 637 640 var res = document.implementation.createDocument(null, 'html', null); 638 641 var range = document.createRange(); 639 642 range.setStartAfter(document.body); 640 res.documentElement.appendChild( 641 res.importNode(range.createContextualFragment(str), true) 642 ); 643 res.documentElement 644 .appendChild(res.importNode(range.createContextualFragment(str), true)); 643 645 return res; 644 646 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)