Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fuckms-refreshtokensync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
msc
fuckms-refreshtokensync
Commits
ecf30cd0
There was an error fetching the commit references. Please try again later.
Commit
ecf30cd0
authored
7 years ago
by
didierfred
Browse files
Options
Downloads
Patches
Plain Diff
Implements new storage format
parent
a8f48db1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
background.js
+43
-26
43 additions, 26 deletions
background.js
popup/config.js
+35
-21
35 additions, 21 deletions
popup/config.js
with
78 additions
and
47 deletions
background.js
+
43
−
26
View file @
ecf30cd0
...
@@ -10,27 +10,46 @@
...
@@ -10,27 +10,46 @@
"
use strict
"
;
"
use strict
"
;
var
targetPage
=
"
https://httpbin.org/*
"
;
//var targetPage = "https://httpbin.org/*";
var
modifyTable
=
[];
//var modifyTable = [];
var
config
;
var
started
=
"
off
"
;
var
started
=
"
off
"
;
//
I
f
no table stored , use and store a default one
//
i
f
configuration exist
if
(
!
localStorage
.
getItem
(
'
modifyTable
'
))
if
(
localStorage
.
getItem
(
'
config
'
))
{
{
modifyTable
=
[
console
.
log
(
"
Load standard config
"
);
[
"
add
"
,
"
test_header_name
"
,
"
test_header_value
"
,
"
on
"
],
config
=
JSON
.
parse
(
localStorage
.
getItem
(
'
config
'
));
];
localStorage
.
setItem
(
"
modifyTable
"
,
JSON
.
stringify
(
modifyTable
));
}
}
else
else
{
{
modifyTable
=
JSON
.
parse
(
localStorage
.
getItem
(
"
modifyTable
"
));
// else check if old config exist
if
(
localStorage
.
getItem
(
'
targetPage
'
)
&&
localStorage
.
getItem
(
'
modifyTable
'
))
{
console
.
log
(
"
Load old config
"
);
var
headers
=
[];
var
modifyTable
=
JSON
.
parse
(
localStorage
.
getItem
(
"
modifyTable
"
));
for
(
var
to_modify
of
modifyTable
)
{
headers
.
push
({
action
:
to_modify
[
0
],
header_name
:
to_modify
[
1
],
header_value
:
to_modify
[
2
],
status
:
to_modify
[
3
]});
}
config
=
{
format_version
:
"
1.0
"
,
target_page
:
localStorage
.
getItem
(
'
targetPage
'
),
headers
:
headers
};
// save old config in new format
localStorage
.
setItem
(
"
config
"
,
JSON
.
stringify
(
config
));
}
//else no config exists, create a default one
else
{
console
.
log
(
"
Load default config
"
);
var
headers
=
[];
headers
.
push
({
action
:
"
add
"
,
header_name
:
"
test_header_name
"
,
header_value
:
"
test_header_value
"
,
status
:
"
on
"
});
config
=
{
format_version
:
"
1.0
"
,
target_page
:
"
https://httpbin.org/*
"
,
headers
:
headers
};
// save configuration
localStorage
.
setItem
(
"
config
"
,
JSON
.
stringify
(
config
));
}
}
}
// If no target page stored , use a default one
if
(
!
localStorage
.
getItem
(
'
targetPage
'
))
localStorage
.
setItem
(
'
targetPage
'
,
targetPage
);
else
targetPage
=
localStorage
.
getItem
(
'
targetPage
'
);
// If no started value stored , use a default one
// If no started value stored , use a default one
if
(
!
localStorage
.
getItem
(
'
started
'
))
localStorage
.
setItem
(
'
started
'
,
started
);
if
(
!
localStorage
.
getItem
(
'
started
'
))
localStorage
.
setItem
(
'
started
'
,
started
);
else
started
=
localStorage
.
getItem
(
'
started
'
);
else
started
=
localStorage
.
getItem
(
'
started
'
);
...
@@ -41,7 +60,6 @@ if (started=="on")
...
@@ -41,7 +60,6 @@ if (started=="on")
browser
.
browserAction
.
setIcon
({
path
:
"
icons/modify-green-32.png
"
});
browser
.
browserAction
.
setIcon
({
path
:
"
icons/modify-green-32.png
"
});
}
}
// listen for change in configuration or start/stop
// listen for change in configuration or start/stop
browser
.
runtime
.
onMessage
.
addListener
(
notify
);
browser
.
runtime
.
onMessage
.
addListener
(
notify
);
...
@@ -53,29 +71,29 @@ browser.runtime.onMessage.addListener(notify);
...
@@ -53,29 +71,29 @@ browser.runtime.onMessage.addListener(notify);
function
rewriteHeader
(
e
)
function
rewriteHeader
(
e
)
{
{
for
(
var
to_modify
of
modifyTable
)
for
(
var
to_modify
of
config
.
headers
)
{
{
if
(
to_modify
[
3
]
==
"
on
"
)
if
(
to_modify
.
status
==
"
on
"
)
{
{
if
(
to_modify
[
0
]
==
"
add
"
)
if
(
to_modify
.
action
==
"
add
"
)
{
{
var
new_header
=
{
"
name
"
:
to_modify
[
1
]
,
"
value
"
:
to_modify
[
2
]
};
var
new_header
=
{
"
name
"
:
to_modify
.
header_name
,
"
value
"
:
to_modify
.
header_value
};
e
.
requestHeaders
.
push
(
new_header
);
e
.
requestHeaders
.
push
(
new_header
);
}
}
else
if
(
to_modify
[
0
]
==
"
modify
"
)
else
if
(
to_modify
.
action
==
"
modify
"
)
{
{
for
(
var
header
of
e
.
requestHeaders
)
for
(
var
header
of
e
.
requestHeaders
)
{
{
if
(
header
.
name
.
toLowerCase
()
==
to_modify
[
1
]
.
toLowerCase
())
header
.
value
=
to_modify
[
2
]
;
if
(
header
.
name
.
toLowerCase
()
==
to_modify
.
header_name
.
toLowerCase
())
header
.
value
=
to_modify
.
header_value
;
}
}
}
}
else
if
(
to_modify
[
0
]
==
"
delete
"
)
else
if
(
to_modify
.
action
==
"
delete
"
)
{
{
var
index
=
-
1
;
var
index
=
-
1
;
for
(
var
i
=
0
;
i
<
e
.
requestHeaders
.
length
;
i
++
)
for
(
var
i
=
0
;
i
<
e
.
requestHeaders
.
length
;
i
++
)
{
{
if
(
e
.
requestHeaders
[
i
].
name
.
toLowerCase
()
==
to_modify
[
1
]
.
toLowerCase
())
index
=
i
;
if
(
e
.
requestHeaders
[
i
].
name
.
toLowerCase
()
==
to_modify
.
header_name
.
toLowerCase
())
index
=
i
;
}
}
if
(
index
!=-
1
)
if
(
index
!=-
1
)
{
{
...
@@ -101,8 +119,7 @@ function notify(message)
...
@@ -101,8 +119,7 @@ function notify(message)
{
{
if
(
message
==
"
reload
"
)
if
(
message
==
"
reload
"
)
{
{
modifyTable
=
JSON
.
parse
(
localStorage
.
getItem
(
"
modifyTable
"
));
config
=
JSON
.
parse
(
localStorage
.
getItem
(
"
config
"
));
targetPage
=
localStorage
.
getItem
(
'
targetPage
'
);
if
(
started
==
"
on
"
)
if
(
started
==
"
on
"
)
{
{
browser
.
webRequest
.
onBeforeSendHeaders
.
removeListener
(
rewriteHeader
);
browser
.
webRequest
.
onBeforeSendHeaders
.
removeListener
(
rewriteHeader
);
...
@@ -132,7 +149,7 @@ function notify(message)
...
@@ -132,7 +149,7 @@ function notify(message)
function
addListener
()
function
addListener
()
{
{
browser
.
webRequest
.
onBeforeSendHeaders
.
addListener
(
rewriteHeader
,
browser
.
webRequest
.
onBeforeSendHeaders
.
addListener
(
rewriteHeader
,
{
urls
:
[
target
P
age
]},
{
urls
:
[
config
.
target
_p
age
]},
[
"
blocking
"
,
"
requestHeaders
"
]);
[
"
blocking
"
,
"
requestHeaders
"
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
popup/config.js
+
35
−
21
View file @
ecf30cd0
...
@@ -13,14 +13,14 @@ var line_number = 1;
...
@@ -13,14 +13,14 @@ var line_number = 1;
var
started
=
"
off
"
;
var
started
=
"
off
"
;
window
.
onload
=
function
()
{
window
.
onload
=
function
()
{
var
config
Table
=
JSON
.
parse
(
localStorage
.
getItem
(
"
modifyTable
"
));
var
config
=
JSON
.
parse
(
localStorage
.
getItem
(
"
config
"
));
for
(
var
to_add
of
config
Table
)
appendLine
(
to_add
[
0
],
to_add
[
1
],
to_add
[
2
],
to_add
[
3
]
);
for
(
var
to_add
of
config
.
headers
)
appendLine
(
to_add
.
action
,
to_add
.
header_name
,
to_add
.
header_value
,
to_add
.
status
);
document
.
getElementById
(
'
save_button
'
).
addEventListener
(
'
click
'
,
function
(
e
)
{
save_data
();});
document
.
getElementById
(
'
save_button
'
).
addEventListener
(
'
click
'
,
function
(
e
)
{
save_data
();});
document
.
getElementById
(
'
export_button
'
).
addEventListener
(
'
click
'
,
function
(
e
)
{
export_data
();});
document
.
getElementById
(
'
export_button
'
).
addEventListener
(
'
click
'
,
function
(
e
)
{
export_data
();});
document
.
getElementById
(
'
import_button
'
).
addEventListener
(
'
c
hange
'
,
function
(
e
)
{
import_data
(
e
);});
document
.
getElementById
(
'
import_button
'
).
addEventListener
(
'
c
lick
'
,
function
(
e
)
{
import_data
(
e
);});
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
=
localStorage
.
getItem
(
"
target
P
age
"
)
;
document
.
getElementById
(
'
targetPage
'
).
value
=
config
.
target
_p
age
;
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
"
;
}
;
}
;
...
@@ -47,7 +47,32 @@ document.getElementById('delete_button'+line_number).addEventListener('click',fu
...
@@ -47,7 +47,32 @@ document.getElementById('delete_button'+line_number).addEventListener('click',fu
line_number
++
;
line_number
++
;
}
}
function
create_configuration_data
()
{
var
tr_elements
=
document
.
querySelectorAll
(
"
#config_tab tr
"
);
var
headers
=
[];
for
(
i
=
1
;
i
<
tr_elements
.
length
;
i
++
)
// ignore line 1 which is the table header
{
var
action
=
tr_elements
[
i
].
childNodes
[
0
].
childNodes
[
0
].
value
;
var
header_name
=
tr_elements
[
i
].
childNodes
[
1
].
childNodes
[
0
].
value
;
var
header_value
=
tr_elements
[
i
].
childNodes
[
2
].
childNodes
[
0
].
value
;
var
status
=
tr_elements
[
i
].
childNodes
[
3
].
childNodes
[
0
].
value
;
headers
.
push
({
action
:
action
,
header_name
:
header_name
,
header_value
:
header_value
,
status
:
status
});
}
var
to_export
=
{
format_version
:
"
1.0
"
,
target_page
:
document
.
getElementById
(
'
targetPage
'
).
value
,
headers
:
headers
};
console
.
log
(
JSON
.
stringify
(
to_export
));
return
JSON
.
stringify
(
to_export
);
}
function
save_data
()
{
localStorage
.
setItem
(
"
config
"
,
create_configuration_data
());
browser
.
runtime
.
sendMessage
(
"
reload
"
);
}
/**
function save_data ()
function save_data ()
{
{
var tr_elements = document.querySelectorAll("#config_tab tr");
var tr_elements = document.querySelectorAll("#config_tab tr");
...
@@ -65,28 +90,18 @@ function save_data ()
...
@@ -65,28 +90,18 @@ function save_data ()
localStorage.setItem("targetPage",document.getElementById('targetPage').value);
localStorage.setItem("targetPage",document.getElementById('targetPage').value);
browser.runtime.sendMessage("reload");
browser.runtime.sendMessage("reload");
}
}
**/
function
export_data
()
function
export_data
()
{
{
// Create file data
// Create file data
var
tr_elements
=
document
.
querySelectorAll
(
"
#config_tab tr
"
);
var
to_export
=
create_configuration_data
();
var
headers
=
[];
for
(
i
=
1
;
i
<
tr_elements
.
length
;
i
++
)
// ignore line 1 which is the table header
{
var
action
=
tr_elements
[
i
].
childNodes
[
0
].
childNodes
[
0
].
value
;
var
header_name
=
tr_elements
[
i
].
childNodes
[
1
].
childNodes
[
0
].
value
;
var
header_value
=
tr_elements
[
i
].
childNodes
[
2
].
childNodes
[
0
].
value
;
var
status
=
tr_elements
[
i
].
childNodes
[
3
].
childNodes
[
0
].
value
;
headers
.
push
({
action
:
action
,
header_name
:
header_name
,
header_value
:
header_value
,
status
:
status
});
}
var
to_export
=
{
format_version
:
"
1.0
"
,
target_page
:
document
.
getElementById
(
'
targetPage
'
).
value
,
headers
:
headers
};
console
.
log
(
JSON
.
stringify
(
to_export
));
// Create file to save
// Create file to save
var
a
=
document
.
createElement
(
'
a
'
);
var
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
'
data:attachment/json,
'
+
encodeURIComponent
(
JSON
.
stringify
(
to_export
)
)
;
a
.
href
=
'
data:attachment/json,
'
+
encodeURIComponent
(
to_export
);
a
.
target
=
'
download
'
;
a
.
target
=
'
download
'
;
a
.
download
=
'
SimpleModifyHeader.conf
'
;
a
.
download
=
'
SimpleModifyHeader.conf
'
;
...
@@ -99,7 +114,6 @@ function export_data()
...
@@ -99,7 +114,6 @@ function export_data()
function
import_data
(
evt
)
function
import_data
(
evt
)
{
{
// create an input field in the iframe
// create an input field in the iframe
var
input
=
document
.
createElement
(
"
input
"
);
var
input
=
document
.
createElement
(
"
input
"
);
input
.
type
=
"
file
"
;
input
.
type
=
"
file
"
;
...
@@ -120,7 +134,7 @@ function readSingleFile(e)
...
@@ -120,7 +134,7 @@ function readSingleFile(e)
var
reader
=
new
FileReader
();
var
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
reader
.
onload
=
function
(
e
)
{
{
var
contents
=
e
.
target
.
result
;
var
contents
=
e
.
target
.
result
;
var
config
=
""
;
var
config
=
""
;
try
try
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment