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: Send request on demand, always link for release builds, falling back to releases overview Created Feb. 5, 2016, 2:09 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
« no previous file with comments | « 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,67 @@
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;
+
+ // Don't link version for development builds
+ if (info.addonVersion.split(".").length > 3)
+ return;
+
+ E("version").setAttribute("href", "#");
+ E("version").addEventListener("click", function(event)
+ {
+ event.preventDefault();
+
+ fetch("https://adblockplus.org/atom/?section=releases&limit=100").then(function(response)
+ {
+ 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)
+ 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)
+ return href;
+ }
+ }
+ },
+ function()
+ {
+ return null;
+ }
+ ).then(function(url)
+ {
+ if (url)
+ document.location.href = url;
+ else
+ getDocLink("releases", function(link)
+ {
+ document.location.href = link;
+ });
+ });
});
getDocLink("contribute", function(link)
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld