From 0f7f6296f335a28816b7fddad7f5ce229bbb1943 Mon Sep 17 00:00:00 2001 From: Daniel Brunner <0xFEEDC0DE64@gmail.com> Date: Fri, 19 Jan 2018 09:32:20 +0100 Subject: [PATCH] Added request.js --- manifest.json | 11 +++++++++++ request.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 manifest.json create mode 100644 request.js diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..63ca0d4 --- /dev/null +++ b/manifest.json @@ -0,0 +1,11 @@ +{ + "manifest_version": 2, + + "name": "Qt docs links fix", + "description": "This extension fixes old Qt docs links.", + "version": "1.0", + "permissions": [ "webRequest", "webRequestBlocking", "", "tabs" ], + "background": { + "scripts": ["request.js"] + } +} diff --git a/request.js b/request.js new file mode 100644 index 0000000..e216d33 --- /dev/null +++ b/request.js @@ -0,0 +1,33 @@ +chrome.webRequest.onBeforeRequest.addListener(function(details) { + let url = details.url; + + for(expression of [ + /^https?:\/\/doc\.qt\.io\/qt-[0-9\.]+(.*)$/g, + /^https?:\/\/doc\.qt\.io\/archives\/qt-[0-9\.]+(.*)$/g, + /^https?:\/\/developer\.qt\.nokia\.com\/doc\/qt-[0-9\.]+(.*)$/g, + /^https?:\/\/qt\.nokia\.com\/doc(.*)$/g, + /^https?:\/\/doc\.qt\.nokia\.com\/(?:latest|stable|[0-9\.]+)(.*)$/g, + /^https?:\/\/doc\.trolltech\.com\/[0-9\.]+(.*)$/g + ]) { + let match = expression.exec(url); + if(match !== null) { + return { redirectUrl: 'https://doc.qt.io/qt-5' + match[1] }; + }; + } + + { + let match = /https?:\/\/bugreports\.qt\.nokia\.com\/(.*)$/g.exec(url); + if(match !== null) { + return { redirectUrl: 'https://bugreports.qt.io/' + match[1] }; + }; + } + + { + let match = /https?:\/\/lists\.qt\.nokia\.com\/(.*)$/g.exec(url); + if(match !== null) { + return { redirectUrl: 'http://lists.qt-project.org\/' + match[1] }; + }; + } +}, { + urls : [""] +}, ["blocking"]);