Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: options.js

Issue 29335794: Proof-of-concept: Link version to corresponding announcement (Closed)
Patch Set: Always send request, no link if no release post found Created Feb. 5, 2016, 1:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« messageResponder.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -646,15 +646,47 @@
ext.backgroundPage.sendMessage(
{
type: "app.get",
- what: "addonVersion"
+ what: "info"
},
- function(addonVersion)
+ function(info)
{
- E("abp-version").textContent = addonVersion;
- });
- getDocLink("releases", function(link)
- {
- E("link-version").setAttribute("href", link);
+ E("abp-version").textContent = info.addonVersion;
+
+ fetch("https://adblockplus.org/atom/?section=releases&limit=100").then(function(response)
Thomas Greiner 2016/02/05 14:24:37 We shouldn't ping our servers everytime someone op
Wladimir Palant 2016/02/05 14:29:44 Indeed. If we need this feature we need to set up
Sebastian Noack 2016/02/05 14:37:18 Please note the alternative approach in patch set
+ {
+ return repsonse.ok ? response.text() : "";
+ }).then(
+ function(text)
+ {
+ var doc = new DOMParser().parseFromString(text, "application/xml");
+ var entries = doc.getElementsByTagName("entry");
+ for (var i = 0; i < entries.length; i++)
+ {
+ var entry = entries[i];
+ var title = entry.getElementsByTagName("title")[0];
+ if (!title)
+ continue;
+
+ var lowerCaseTitleText = title.textContent.toLowerCase();
+ if (lowerCaseTitleText.split(/\W+/).indexOf(info.application) == -1)
Thomas Greiner 2016/02/05 14:24:37 That doesn't seem too reliable because it's more o
Sebastian Noack 2016/02/05 14:37:18 I guess we could omit that check as well. Not sure
+ continue;
+ if (lowerCaseTitleText.split(/\s+/).indexOf(info.addonVersion) == -1)
+ continue;
+
+ var links = entry.getElementsByTagName("link");
+ for (var j = 0; j < links.length; j++)
+ {
+ var link = links[j];
+ var href = link.getAttribute("href");
+
+ if (link.getAttribute("rel") == "alternate" && href)
+ {
+ E("version").setAttribute("href", href);
+ return;
+ }
+ }
+ }
+ }).catch(function() {});
});
getDocLink("contribute", function(link)
« messageResponder.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld