Skip to content
Snippets Groups Projects
Commit d5865a08 authored by didierfred's avatar didierfred
Browse files

finalise the url pattern control

parent 807422d5
No related branches found
No related tags found
No related merge requests found
...@@ -8,12 +8,18 @@ The rules table contains lines with the following parameters : ...@@ -8,12 +8,18 @@ The rules table contains lines with the following parameters :
- action : add, modify or delete a header field - action : add, modify or delete a header field
- header field name - header field name
- header field value - header field value
- comment : a comment
- status : on if the modification is active , off otherwise - status : on if the modification is active , off otherwise
We can choose the urls on which the modifications applies by modifying the url pattern. We can choose the urls on which the modifications applies by modifying the url pattern. The url pattern must follow the syntaxe define by https://developer.chrome.com/extensions/match_patterns
To save and apply the modification , you need to click on the save button To save and apply the modification , you need to click on the save button
It's possible to:
- export the configuration in a file (json format)
- import the configuration from a file , it support the format of the Modifyheaders plugin
The extension can be start and stop via the button on the top right. The extension can be start and stop via the button on the top right.
The code is opensource under Mozilla Public License 2.0 The code is opensource under Mozilla Public License 2.0
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* @author didierfred@gmail.com * @author didierfred@gmail.com
* @version 0.1 * @version 0.2
*/ */
...@@ -149,7 +149,7 @@ function notify(message) ...@@ -149,7 +149,7 @@ function notify(message)
function addListener() function addListener()
{ {
var target = config.target_page; var target = config.target_page;
if ((target=="*")||(target=="")||(target==" "))target="<all_urls>"; if ((target=="*")||(target=="")||(target==" ")) target="<all_urls>";
browser.webRequest.onBeforeSendHeaders.addListener(rewriteHeader, browser.webRequest.onBeforeSendHeaders.addListener(rewriteHeader,
{urls: [target]}, {urls: [target]},
......
...@@ -53,7 +53,7 @@ color: #008CBA; ...@@ -53,7 +53,7 @@ color: #008CBA;
<td width="450"> <td width="450">
Url Pattern* : <input size="50" id="targetPage" type="text" value=""></input> Url Pattern* : <input size="50" id="targetPage" type="text" value="">
</td> </td>
<td width="270" align="right"> <td width="270" align="right">
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* @author didierfred@gmail.com * @author didierfred@gmail.com
* @version 0.1 * @version 0.2
*/ */
...@@ -21,6 +21,7 @@ window.onload = function() { ...@@ -21,6 +21,7 @@ window.onload = function() {
document.getElementById('add_button').addEventListener('click',function (e) {appendLine("add","-","-","","off");}); document.getElementById('add_button').addEventListener('click',function (e) {appendLine("add","-","-","","off");});
document.getElementById('start_img').addEventListener('click',function (e) {start_modify();}); document.getElementById('start_img').addEventListener('click',function (e) {start_modify();});
document.getElementById('targetPage').value=config.target_page; document.getElementById('targetPage').value=config.target_page;
document.getElementById('targetPage').addEventListener('keyup',function (e) {checkTargetPageField();});
started = localStorage.getItem("started"); started = localStorage.getItem("started");
if (started=="on") document.getElementById("start_img").src = "img/stop.png"; if (started=="on") document.getElementById("start_img").src = "img/stop.png";
} ; } ;
...@@ -69,17 +70,24 @@ function create_configuration_data() ...@@ -69,17 +70,24 @@ function create_configuration_data()
return JSON.stringify(to_export); return JSON.stringify(to_export);
} }
// check if url pattern is valid , if not , set the font color to red
function checkTargetPageField()
{
if (isTargetValid(document.getElementById('targetPage').value)) document.getElementById('targetPage').style.color="black";
else document.getElementById('targetPage').style.color="red";
}
// check if url pattern is valid // check if url pattern is valid
function isTargetValid(target) function isTargetValid(target)
{ {
if (target=="") return true; if (target=="") return true;
if (target==" ") return true; if (target==" ") return true;
if (target=="*") return true; if (target=="*") return true;
return target.match("(http|https):\/\/.[^\*]*\/"); return target.match("(http|https|[\*]):\/\/([\*][\.][^\*]*|[^\*]*|[\*])\/");
} }
function save_data () function save_data()
{ {
if (!isTargetValid(document.getElementById('targetPage').value)) if (!isTargetValid(document.getElementById('targetPage').value))
{ {
...@@ -143,6 +151,8 @@ function readSingleFile(e) ...@@ -143,6 +151,8 @@ function readSingleFile(e)
// check file format // check file format
if (config.format_version && config.target_page) if (config.format_version && config.target_page)
{ {
// if url pattern invalid , set to ""
if (!isTargetValid(config.target_page)) config.target_page="";
// store the conf in the local storage // store the conf in the local storage
localStorage.setItem("config",contents); localStorage.setItem("config",contents);
// load the new conf // load the new conf
......
screenshot.png

16.6 KiB | W: | H:

screenshot.png

45.3 KiB | W: | H:

screenshot.png
screenshot.png
screenshot.png
screenshot.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment