@@ -39,9 +39,6 @@ init();
39
39
40
40
// checks if the page is google web cache and referred by this extension
41
41
function checkIfGoogleWebCache ( ) {
42
- // console.log(
43
- // "Checking if this site is google webcache and referred by medium-parser extension"
44
- // );
45
42
const url = new URL ( document . URL ) ;
46
43
47
44
if (
@@ -88,7 +85,7 @@ function handleURLChange() {
88
85
}
89
86
90
87
function runMedium ( url ) {
91
- // check the url
88
+ // check the url
92
89
const u = new URL ( url ) ;
93
90
94
91
// check if it is a page
@@ -99,59 +96,36 @@ function runMedium(url) {
99
96
ignoreURLs . indexOf ( u . pathname ) == - 1 &&
100
97
u . pathname . split ( "/" ) . filter ( ( e ) => e ) . length >= 1
101
98
) {
102
- // get the title
103
-
104
- var leftDiv = document . createElement ( "div" ) ; //Create left div
105
- leftDiv . id = "medium-parser" ; //Assign div id
99
+ var leftDiv = document . createElement ( "div" ) ;
100
+ leftDiv . id = "medium-parser" ;
106
101
leftDiv . setAttribute (
107
102
"style" ,
108
103
"position:absolute;z-index:1;top:150px;right:150px;"
109
- ) ; //Set div attributes
110
- a = document . createElement ( "a" ) ;
111
- a . href = `http://webcache.googleusercontent.com/search?q=cache:${ url } &strip=0&vwsrc=1&referer=medium-parser` ; // Instead of calling setAttribute
112
- a . innerHTML = "Open in Google Cache" ;
113
- a . setAttribute (
114
- "style" ,
115
- "padding:14px 25px; color:white; background: #242424; display:block;text-align:center;"
116
- ) ; //Set div attributes
117
- a . setAttribute ( "target" , "_blank" ) ; //Set div attributes
118
-
119
- archive = document . createElement ( "a" ) ;
120
- archive . href = `https://archive.today?url=${ url } &run=1&referer=medium-parser` ; // Instead of calling setAttribute
121
- archive . innerHTML = "Open in Archive" ;
122
- archive . setAttribute (
123
- "style" ,
124
- "padding:14px 25px; color:white; background: #242424; display:block; margin-top:10px;text-align:center;"
125
- ) ; //Set div attributes
126
- archive . setAttribute ( "target" , "_blank" ) ; //Set div attributes
127
-
128
- // old API
129
- oldAPI = document . createElement ( "a" ) ;
130
- oldAPI . href = `https://medium-parser.vercel.app/?url=${ url } ` ; // Instead of calling setAttribute
131
- oldAPI . innerHTML = "Open in Proxy API" ;
132
- oldAPI . setAttribute (
133
- "style" ,
134
- "padding:14px 25px; color:white; background: #242424; display:block; margin-top:10px;text-align:center;"
135
- ) ; //Set div attributes
136
- oldAPI . setAttribute ( "target" , "_blank" ) ; //Set div attributes
137
-
138
- // add readmedium.com
139
- readMedium = document . createElement ( "a" ) ;
140
- readMedium . href = `https://readmedium.com/${ url } ` ; // Instead of calling setAttribute
141
- readMedium . innerHTML = "Open in Read-Medium" ;
142
- readMedium . setAttribute (
143
- "style" ,
144
- "padding:14px 25px; color:white; background: #242424; display:block; margin-top:10px;text-align:center;"
145
- ) ; //Set div attributes
146
- readMedium . setAttribute ( "target" , "_blank" ) ; //Set div attributes
147
-
148
- messageEl = createMessageElement ( ) ;
104
+ ) ;
105
+
106
+ let buttons = [
107
+ createButton (
108
+ "Open in Google Cache" ,
109
+ `http://webcache.googleusercontent.com/search?q=cache:${ url } &strip=0&vwsrc=1&referer=medium-parser`
110
+ ) ,
111
+ createButton ( "Open in Read-Medium" , `https://readmedium.com/en/${ url } ` ) ,
112
+ createButton ( "Open in Freedium" , `https://freedium.cfd/${ url } ` ) ,
113
+ createButton (
114
+ "Open in Archive" ,
115
+ `https://archive.today?url=${ url } &run=1&referer=medium-parser`
116
+ ) ,
117
+ createButton (
118
+ "Open in Proxy API" ,
119
+ `https://medium-parser.vercel.app/?url=${ url } `
120
+ ) ,
121
+ createMessageElement ( ) ,
122
+ createSupportElement ( ) ,
123
+ ] ;
124
+
125
+ buttons . forEach ( ( button ) => {
126
+ leftDiv . appendChild ( button ) ;
127
+ } ) ;
149
128
150
- leftDiv . appendChild ( a ) ; // Append the link to the div
151
- leftDiv . appendChild ( readMedium ) ;
152
- leftDiv . appendChild ( archive ) ;
153
- leftDiv . appendChild ( oldAPI ) ;
154
- leftDiv . appendChild ( messageEl ) ;
155
129
root . appendChild ( leftDiv ) ; // A
156
130
} else {
157
131
// remove the element
@@ -208,20 +182,33 @@ function createMessageElement() {
208
182
"style" ,
209
183
"padding:2px 4px; color:#242424; display:block; text-align:left;max-width: 212px;font-size: 0.83em;border: 1px solid black; margin-top:10px; position:relative;"
210
184
) ;
211
-
212
- // cross el
213
- // crossEl = document.createElement("div");
214
- // crossEl.innerHTML = "✕";
215
- // crossEl.setAttribute(
216
- // "style",
217
- // "position: absolute;right: -1px;top: -1px;background: #242424;padding: 0px 4px;margin: 0; color: white;cursor: pointer;"
218
- // );
219
- // crossEl.addEventListener("click", removeMessageEl);
220
-
221
- // messageEl.appendChild(crossEl);
222
185
return messageEl ;
223
186
}
224
187
188
+ function createSupportElement ( ) {
189
+ btnEl = document . createElement ( "div" ) ;
190
+ btnEl . innerHTML =
191
+ "Having an issue ? <a href='https://github.com/Xatta-Trone/medium-parser-extension/issues/new' target='_blank' style='color: #ff4757;text-decoration: underline;'>Open a ticket</a>" ;
192
+ btnEl . setAttribute (
193
+ "style" ,
194
+ "padding:2px 4px; color:#242424; display:block; text-align:left;max-width: 212px;font-size: 0.83em; margin-top:10px; position:relative;"
195
+ ) ;
196
+ return btnEl ;
197
+ }
198
+
225
199
function removeMessageEl ( e ) {
226
200
e . target . parentNode . remove ( ) ;
227
201
}
202
+
203
+ // create the button UI
204
+ function createButton ( text , url ) {
205
+ btnEl = document . createElement ( "a" ) ;
206
+ btnEl . href = url ;
207
+ btnEl . innerHTML = text ;
208
+ btnEl . setAttribute (
209
+ "style" ,
210
+ "padding:14px 25px; color:white; background: #242424; display:block; margin-top:10px;text-align:center;"
211
+ ) ;
212
+ btnEl . setAttribute ( "target" , "_blank" ) ;
213
+ return btnEl ;
214
+ }
0 commit comments