File tree Expand file tree Collapse file tree 5 files changed +60
-18
lines changed
Expand file tree Collapse file tree 5 files changed +60
-18
lines changed Original file line number Diff line number Diff line change 1+ # javascript firefox addon
2+
3+ An addon that lets you run automatically run some javascript when you visit a
4+ particular domain. Good for adding your own little QoL fixes.
5+
6+ Available on [ the Firefox addon store] ( https://addons.mozilla.org/en-GB/firefox/addon/javascript/ ) .
Original file line number Diff line number Diff line change 99< textarea id =javascript rows =20 >
1010</ textarea >
1111
12- < button id ="letters-js " title ="Open options page ">
12+ < button id ="rerun " title ="Rerun " label ="Rerun the javascript ">
13+ ↻
14+ </ button >
15+ < button id ="letters-js " title ="Open options page " label ="Open options page ">
1316 JS
1417</ button >
1518
Original file line number Diff line number Diff line change 11let javascript = document . getElementById ( "javascript" )
2- let button = document . getElementById ( "letters-js" )
2+ let lettersButton = document . getElementById ( "letters-js" )
3+ let rerunButton = document . getElementById ( "rerun" )
34
4- button . addEventListener ( "click" , ( ) => {
5+ rerunButton . addEventListener ( "click" , async ( ) => {
6+ let [ tab ] = await browser . tabs . query ( {
7+ currentWindow : true ,
8+ active : true ,
9+ } )
10+ await browser . tabs . sendMessage ( tab . id , { rerun : true } )
11+ } )
12+
13+ lettersButton . addEventListener ( "click" , ( ) => {
514 browser . runtime . openOptionsPage ( )
615 window . close ( )
716} )
@@ -12,16 +21,9 @@ let editor = CodeMirror.fromTextArea(javascript, {
1221 matchBrackets : true ,
1322 tabSize : 2 ,
1423 indentWithTabs : true ,
15- lint : CodeMirror . lint . javascript ,
1624 theme : "monokai"
1725} )
1826
19- editor . setOption ( "lint" , {
20- options : {
21- esversion : 6
22- }
23- } )
24-
2527let defaultCode = `\
2628// enter some javascript here and it will run
2729// on every page on this domain (location.host)
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ textarea, .CodeMirror {
3131 cursor : pointer;
3232}
3333
34+ # rerun {
35+ background : # f7df1e ;
36+ margin-left : 1ch ;
37+
38+ border : 1px solid black;
39+ cursor : pointer;
40+ }
41+
42+ # rerun : hover {
43+ background : white;
44+ }
45+
3446@font-face {
3547 font-family : "Reem Kufi" ;
3648 font-style : normal;
Original file line number Diff line number Diff line change 1- browser . storage . local . get ( ) . then ( store => {
2- let javascript = store [ location . host ]
1+ function id ( ) {
2+ return `javascript.chee.${ location . host } `
3+ }
34
4- if ( ! javascript ) {
5- return
6- }
5+ function inject ( ) {
6+ browser . storage . local . get ( ) . then ( store => {
7+ let javascript = store [ location . host ]
8+
9+ if ( ! javascript ) {
10+ return
11+ }
12+
13+ let script = document . createElement ( "script" )
14+ script . id = id ( )
15+ script . textContent = javascript
16+ document . body . append ( script )
17+ } )
18+ }
719
8- let script = document . createElement ( 'script' )
9- script . textContent = javascript
10- document . body . append ( script )
20+ inject ( )
21+
22+ browser . runtime . onMessage . addListener ( request => {
23+ if ( request . rerun ) {
24+ let script = document . getElementById ( id ( ) )
25+ if ( script ) {
26+ document . body . removeChild ( script )
27+ }
28+ inject ( )
29+ }
1130} )
You can’t perform that action at this time.
0 commit comments