objects custom format."
197 | },
198 | "imgObjectsCustomFormat": {
199 | "message": "Пользовательский формат копируемых объектов
: ",
200 | "description": "UI setting - [Analyze URLs] - Copy
objects custom format."
201 | },
202 | "imageUrlsCustomFormat": {
203 | "message": "Пользовательский формат копируемых URL-адресов изображений: ",
204 | "description": "UI setting - [Analyze URLs] - Copy Image URLs custom format."
205 | },
206 | "maxTabsLimit": {
207 | "message": "Максимальное число одновременно открываемых вкладок: ",
208 | "description": "UI setting - [Analyze URLs] - Max tabs limit at once open."
209 | },
210 | "openOneImageDirectly": {
211 | "message": "Открывать ссылку на единственное изображение напрямую",
212 | "description": "UI setting - [Analyze URLs] - Open a single Image link directly."
213 | },
214 | "blobUrlToLocal": {
215 | "message": "Преобразовывать Blob URL в локальные URL-адреса (очень медленно)",
216 | "description": "UI setting - [Analyze URLs] - Blob URLs convert to local images."
217 | },
218 | "toolbarButtonAction": {
219 | "message": "Действие кнопки панели инструментов: ",
220 | "description": "UI setting - [Toolbar button] - Toolbar button action."
221 | },
222 | "keyboardShortcutAction": {
223 | "message": "Действие сочетания клавиш: ",
224 | "description": "UI setting - [keybord shortcut] - keyboard shortcut action."
225 | },
226 | "language":{
227 | "message": "Язык: ",
228 | "description": "UI setting - [Interface] - Language "
229 | },
230 | "improveTrans":{
231 | "message": "Улучшить перевод",
232 | "description": "UI setting - [Interface] - Improve translation "
233 | }
234 | }
235 |
--------------------------------------------------------------------------------
/TextLinkyTool/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
140 |
141 |
142 |
143 |
144 |
145 | URL part text format:
146 |
147 | [[url]] - URL text
148 | [[host]] - URL host text
149 | [[fullhost]] - URL full host text
150 | [[fullpath]] - URL full path text
151 |
152 | [[potocol]] - URL potocol text
153 | [[hostname]] - URL hostname text
154 | [[port]] - URL port text
155 | [[pathname]] - URL pathname text
156 | [[search]] - URL search text
157 | [[hash]] - URL hash text
158 |
159 |
160 | Improve translation:
161 |
162 | Fork the repository from
Github ,
163 | apply your changes and create a pull request.
164 |
165 |
166 |
--------------------------------------------------------------------------------
/TextLinkyTool/options.js:
--------------------------------------------------------------------------------
1 | //page ready
2 | function pageReady() {
3 | commonLookup.getUserTltSetting().then((tlt)=>{
4 | //i18n message support for page elements
5 | document.querySelectorAll("[data-i18n]").forEach(ele => {
6 | let ctxt = commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,ele.getAttribute("data-i18n"));
7 | switch (ele.tagName){
8 | case "INPUT":
9 | ele.value = ctxt;
10 | //case "LABEL": case "OPTION":
11 | default:
12 | ele.textContent = ctxt;
13 | }
14 | });
15 |
16 | //get option settings
17 | showOptionSettings(tlt.userTltSetting);
18 | });
19 |
20 | //Tooltips active
21 | document.querySelectorAll(".tiptxt").forEach((ele)=>{
22 | let tptxt = ele.cloneNode(true);
23 | let boxcss = ele.getAttribute("data-boxcss");
24 | tptxt.attributes.removeNamedItem("data-boxcss");
25 | document.querySelectorAll(`.tipbox.${boxcss}`).forEach((box)=>{ box.appendChild(tptxt.cloneNode(true)); });
26 | });
27 | }
28 |
29 | //custom formats list delete
30 | function listDel(list,idx)
31 | {
32 | clearSavedMessage();
33 | list.querySelectorAll(`[data-idx="${idx}"]`).forEach(ele => ele.remove());
34 | }
35 |
36 | //custom formats list add
37 | function listAdd(list,name,value,idx)
38 | {
39 | clearSavedMessage();
40 | let frag = document.createDocumentFragment();
41 | let inpName = document.createElement("input");
42 | inpName.setAttribute("tpye","text");
43 | inpName.setAttribute("class","listName");
44 | inpName.setAttribute("value",name);
45 | inpName.setAttribute("maxlength","40");
46 | inpName.setAttribute("data-idx",idx.toString());
47 | inpName.addEventListener("change", clearSavedMessage);
48 | inpName.addEventListener("keypress", clearSavedMessage);
49 | frag.appendChild(inpName);
50 | let inpData = document.createElement("input");
51 | inpData.setAttribute("tpye","text");
52 | inpData.setAttribute("class","listData");
53 | inpData.setAttribute("value",value);
54 | inpData.setAttribute("maxlength","200");
55 | inpData.setAttribute("data-idx",idx.toString());
56 | inpData.addEventListener("change", clearSavedMessage);
57 | inpData.addEventListener("keypress", clearSavedMessage);
58 | frag.appendChild(inpData);
59 | let inpDel = document.createElement("input");
60 | inpDel.setAttribute("type","button");
61 | inpDel.setAttribute("class","btnDel");
62 | inpDel.setAttribute("value","-");
63 | inpDel.setAttribute("data-idx",idx.toString());
64 | inpDel.addEventListener("click",function(e){
65 | let list = e.target.parentNode;
66 | let idx = e.target.getAttribute("data-idx");
67 | listDel(list,idx);
68 | changeToolbarAction();
69 | changeKeyboardAction();
70 | });
71 | frag.appendChild(inpDel);
72 | let br = document.createElement("br");
73 | br.setAttribute("data-idx",idx.toString());
74 | frag.appendChild(br);
75 | list.appendChild(frag);
76 | changeToolbarAction();
77 | changeKeyboardAction();
78 | }
79 |
80 | //button add list click event
81 | function btnAddClick(e)
82 | {
83 | let list = document.getElementById(e.target.getAttribute("data-listid"));
84 | let name = e.target.getAttribute("data-name");
85 | let value = e.target.getAttribute("data-value");
86 | let dels = list.querySelectorAll("input.btnDel");
87 | let idx = dels.length==0?0:Number(dels[dels.length-1].getAttribute("data-idx")) + 1;
88 | listAdd(list,name,value,idx);
89 | }
90 |
91 | //get custom formats list data
92 | function getListData(list)
93 | {
94 | let result=[];
95 | if (list==null) {return result;}
96 | let names = list.querySelectorAll(".listName[data-idx]");
97 | let datas = list.querySelectorAll(".listData[data-idx]");
98 | for (let i=0;ires.json());
110 | return data;
111 | }
112 |
113 | //show option settings
114 | function showOptionSettings(setting) {
115 | let frag=null;
116 | document.querySelector("#inpOpenPagesLimit").value = setting.openPagesLimit;
117 | frag=document.createDocumentFragment();
118 | setting.linkCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
119 | document.querySelector("#divLinkCustomFormat").clearElement().appendChild(frag);
120 | frag=null;
121 | frag=document.createDocumentFragment();
122 | setting.tabCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
123 | document.querySelector("#divTabCustomFormat").clearElement().appendChild(frag);
124 | frag=null;
125 | document.querySelector("#selToolbarButtonAction").value = setting.toolbarButtonAction;
126 | document.querySelector("#selKeyboardShortcutAction").value = setting.keyboardShortcutAction;
127 | document.querySelector("#inpFixUrlQuotEnd").checked = setting.fixUrlQuotEnd;
128 | document.querySelector("#inpPuretextFormatDelAroundSpace").checked = setting.puretextFormat.delAroundSpace;
129 | document.querySelector("#inpPuretextFormatDelInvisibleSpace").checked = setting.puretextFormat.delInvisibleSpace;
130 | document.querySelector("#inpPuretextFormatConvertQuotation").checked = setting.puretextFormat.convertQuotation;
131 | document.querySelector("#inpPuretextFormatConvertApostrophe").checked = setting.puretextFormat.convertApostrophe;
132 | document.querySelector("#inpPuretextFormatConvertDash").checked = setting.puretextFormat.convertDash;
133 | document.querySelector("#inpPuretextFormatConvertSpace").checked = setting.puretextFormat.convertSpace;
134 | document.querySelector("#inpPuretextFormatMergeNewline").checked = setting.puretextFormat.mergeNewline;
135 | document.querySelector("#inpPuretextFormatMergeSpace").checked = setting.puretextFormat.mergeSpace;
136 | document.querySelector("#inpPuretextFormatMergeFullwidthSpace").checked = setting.puretextFormat.mergeFullwidthSpace;
137 | document.querySelector("#inpPuretextFormatMergeTabulation").checked = setting.puretextFormat.mergeTabulation;
138 | document.querySelector("#inpPuretextFormatMergeAllTypeSpace").checked = setting.puretextFormat.mergeAllTypeSpace;
139 | document.querySelector("#inpHtmltextFormatWithoutTag").checked = setting.htmltextFormatWithoutTag;
140 | document.querySelector("#inpOpenOneImageDirectly").checked = setting.openOneImageDirectly;
141 | frag=document.createDocumentFragment();
142 | setting.tabsinfoCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
143 | document.querySelector("#divTabsinfoCustomFormat").clearElement().appendChild(frag);
144 | frag=null;
145 | frag=document.createDocumentFragment();
146 | setting.urlsCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
147 | document.querySelector("#divUrlsCustomFormat").clearElement().appendChild(frag);
148 | frag=null;
149 | frag=document.createDocumentFragment();
150 | setting.imageUrlsCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
151 | document.querySelector("#divImageUrlsCustomFormat").clearElement().appendChild(frag);
152 | frag=null;
153 | frag=document.createDocumentFragment();
154 | setting.aObjectsCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
155 | document.querySelector("#divAObjectsCustomFormat").clearElement().appendChild(frag);
156 | frag=null;
157 | frag=document.createDocumentFragment();
158 | setting.imgObjectsCustomFormatList.forEach( function(item,itemidx) { listAdd(frag,item.name,item.data,itemidx); });
159 | document.querySelector("#divImgObjectsCustomFormat").clearElement().appendChild(frag);
160 | frag=null;
161 | document.querySelector("#inpBlobUrlToLocal").checked = setting.blobUrlToLocal;
162 | document.querySelector("#selInterfaceLanguage").value = setting.locale;
163 | changeToolbarAction();
164 | document.querySelector("#selToolbarButtonActionIdx").value = setting.toolbarButtonActionIdx.toString();
165 | changeKeyboardAction();
166 | document.querySelector("#selKeyboardShortcutActionIdx").value = setting.keyboardShortcutActionIdx.toString();
167 | }
168 |
169 | //set option settings
170 | async function setOptionSettings(e) {
171 | let ldata = await getlocaleData(document.querySelector("#selInterfaceLanguage").value);
172 | let tlt = {
173 | openPagesLimit: document.querySelector("#inpOpenPagesLimit").value,
174 | linkCustomFormatList: getListData(document.querySelector("#divLinkCustomFormat")),
175 | tabCustomFormatList: getListData(document.querySelector("#divTabCustomFormat")),
176 | toolbarButtonAction: document.querySelector("#selToolbarButtonAction").value,
177 | toolbarButtonActionIdx: document.querySelector("#selToolbarButtonActionIdx").selectedIndex,
178 | keyboardShortcutAction: document.querySelector("#selKeyboardShortcutAction").value,
179 | keyboardShortcutActionIdx: document.querySelector("#selKeyboardShortcutActionIdx").selectedIndex,
180 | fixUrlQuotEnd: document.querySelector("#inpFixUrlQuotEnd").checked,
181 | puretextFormat: {
182 | delAroundSpace: document.querySelector("#inpPuretextFormatDelAroundSpace").checked,
183 | delInvisibleSpace: document.querySelector("#inpPuretextFormatDelInvisibleSpace").checked,
184 | convertQuotation: document.querySelector("#inpPuretextFormatConvertQuotation").checked,
185 | convertApostrophe: document.querySelector("#inpPuretextFormatConvertApostrophe").checked,
186 | convertDash: document.querySelector("#inpPuretextFormatConvertDash").checked,
187 | convertSpace: document.querySelector("#inpPuretextFormatConvertSpace").checked,
188 | mergeNewline: document.querySelector("#inpPuretextFormatMergeNewline").checked,
189 | mergeSpace: document.querySelector("#inpPuretextFormatMergeSpace").checked,
190 | mergeFullwidthSpace: document.querySelector("#inpPuretextFormatMergeFullwidthSpace").checked,
191 | mergeTabulation: document.querySelector("#inpPuretextFormatMergeTabulation").checked,
192 | mergeAllTypeSpace: document.querySelector("#inpPuretextFormatMergeAllTypeSpace").checked
193 | },
194 | htmltextFormatWithoutTag: document.querySelector("#inpHtmltextFormatWithoutTag").checked,
195 | openOneImageDirectly: document.querySelector("#inpOpenOneImageDirectly").checked,
196 | tabsinfoCustomFormatList: getListData(document.querySelector("#divTabsinfoCustomFormat")),
197 | urlsCustomFormatList: getListData(document.querySelector("#divUrlsCustomFormat")),
198 | imageUrlsCustomFormatList: getListData(document.querySelector("#divImageUrlsCustomFormat")),
199 | aObjectsCustomFormatList: getListData(document.querySelector("#divAObjectsCustomFormat")),
200 | imgObjectsCustomFormatList: getListData(document.querySelector("#divImgObjectsCustomFormat")),
201 | blobUrlToLocal: document.querySelector("#inpBlobUrlToLocal").checked,
202 | locale: document.querySelector("#selInterfaceLanguage").value,
203 | localeData: ldata
204 | }
205 |
206 | //checking settings
207 | if ((tlt.toolbarButtonAction==commonLookup.actlist.copySelectedUrls && tlt.toolbarButtonActionIdx==-1) ||
208 | (tlt.keyboardShortcutAction==commonLookup.actlist.copySelectedUrls && tlt.keyboardShortcutActionIdx==-1))
209 | {
210 | commonLookup.getUserTltSetting().then((tlt)=>{
211 | alert(commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"actUrlFormatEmpty"));
212 | });
213 | return;
214 | }
215 | if ((tlt.toolbarButtonAction==commonLookup.actlist.copySelectedImageUrls && tlt.toolbarButtonActionIdx==-1) ||
216 | (tlt.keyboardShortcutAction==commonLookup.actlist.copySelectedImageUrls && tlt.keyboardShortcutActionIdx==-1))
217 | {
218 | commonLookup.getUserTltSetting().then((tlt)=>{
219 | alert(commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"actImgUrlFormatEmpty"));
220 | });
221 | return;
222 | }
223 |
224 | //save settings
225 | browser.storage.local.set({
226 | "userTltSetting": tlt
227 | });
228 | document.querySelector("#lblSaved").style.visibility = "visible";
229 | }
230 |
231 | //clear saved message
232 | function clearSavedMessage() {
233 | document.querySelector("#lblSaved").style.visibility = "hidden";
234 | }
235 |
236 | //clear saved message
237 | function resetOptionSettings() {
238 | clearSavedMessage();
239 | showOptionSettings(commonLookup.defaultTltSetting);
240 | }
241 |
242 | //fill ActionIdx list
243 | function fillActionIdx(actqs,selqs){
244 | let sel=document.querySelector(selqs);
245 | let list=[];
246 | if (document.querySelector(actqs).value==commonLookup.actlist.copySelectedUrls)
247 | {
248 | list=getListData(document.querySelector("#divUrlsCustomFormat"));
249 | }
250 | if (document.querySelector(actqs).value==commonLookup.actlist.copySelectedImageUrls)
251 | {
252 | list=getListData(document.querySelector("#divImageUrlsCustomFormat"));
253 | }
254 | let frag=document.createDocumentFragment();
255 | list.forEach((item,idx)=>{
256 | let op = document.createElement("option");
257 | op.setAttribute("value",idx.toString());
258 | op.text = (idx+1).toString() + " - " + item.name;
259 | frag.appendChild(op);
260 | });
261 | sel.querySelectorAll("option").forEach(ele => ele.remove());
262 | sel.appendChild(frag);
263 | }
264 |
265 | //change ToolbarButtonAction
266 | function changeToolbarAction(){
267 | fillActionIdx("#selToolbarButtonAction","#selToolbarButtonActionIdx");
268 | }
269 |
270 | //change KeyboardShortcutAction
271 | function changeKeyboardAction(){
272 | fillActionIdx("#selKeyboardShortcutAction","#selKeyboardShortcutActionIdx");
273 | }
274 |
275 |
276 | //page listener
277 | document.addEventListener("DOMContentLoaded", pageReady);
278 | document.querySelector("#inpSaveSettings").addEventListener("click", setOptionSettings);
279 | document.querySelector("#inpResetSettings").addEventListener("click", resetOptionSettings);
280 | document.querySelector("#selToolbarButtonAction").addEventListener("change", changeToolbarAction);
281 | document.querySelector("#divUrlsCustomFormat").addEventListener("focusout",e=> {changeToolbarAction();e.stopPropagation();});
282 | document.querySelector("#selKeyboardShortcutAction").addEventListener("change", changeKeyboardAction);
283 | document.querySelector("#divImageUrlsCustomFormat").addEventListener("focusout",e=> {changeToolbarAction();e.stopPropagation();});
284 | document.querySelectorAll("form input").forEach((e) => e.addEventListener("change", clearSavedMessage));
285 | document.querySelectorAll("form input").forEach((e) => e.addEventListener("keypress", clearSavedMessage));
286 | document.querySelectorAll("select").forEach((e) => e.addEventListener("change", clearSavedMessage));
287 | document.querySelectorAll(".btnAdd").forEach((e) => e.addEventListener("click",btnAddClick));
--------------------------------------------------------------------------------
/TextLinkyTool/background.js:
--------------------------------------------------------------------------------
1 | //Menus Methods
2 | function menuCombine(tab)
3 | {
4 | //Filter block list
5 | let taburl=tab.url;
6 | if (taburl.startsWith("https://addons.mozilla.org/") || taburl.startsWith("moz-extension://") || (taburl.startsWith("about:") && taburl != "about:blank")) {
7 | return;
8 | }
9 |
10 | //Toolbar button enable
11 | browser.browserAction.enable(tab.id);
12 |
13 | //Context menus combine
14 | commonLookup.getUserTltSetting().then((tlt)=>{
15 | browser.menus.create({
16 | id: commonLookup.actlist.copySelectedPuretext + "-0",
17 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedPuretext"),
18 | contexts: ["selection"]
19 | });
20 | browser.menus.create({
21 | id: commonLookup.actlist.copySelectedHtmltext + "-0",
22 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedHtmltext"),
23 | contexts: ["selection"]
24 | });
25 | browser.menus.create({
26 | id: "separator-0",
27 | type: "separator",
28 | contexts: ["selection"]
29 | });
30 | browser.menus.create({
31 | id: commonLookup.actlist.copyLinkName + "-0",
32 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyLinkName"),
33 | contexts: ["link"]
34 | });
35 | browser.menus.create({
36 | id: commonLookup.actlist.copyLinkUrl + "-0",
37 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyLinkUrl"),
38 | contexts: ["link"]
39 | });
40 | tlt.userTltSetting.linkCustomFormatList.forEach((item,idx)=>{
41 | browser.menus.create({
42 | id: commonLookup.actlist.copyLinkFormatText + "-" + idx.toString(),
43 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyLinkFormatText").format(item.name),
44 | contexts: ["link"]
45 | });
46 | });
47 | browser.menus.create({
48 | id: commonLookup.actlist.copyImageUrl + "-0",
49 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyImageUrl"),
50 | contexts: ["image"]
51 | });
52 | browser.menus.create({
53 | id: commonLookup.actlist.showImage + "-0",
54 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"showImage"),
55 | contexts: ["image"]
56 | });
57 | browser.menus.create({
58 | id: "separator-1",
59 | type: "separator",
60 | contexts: ["link", "image"]
61 | });
62 | tlt.userTltSetting.urlsCustomFormatList.forEach((item,idx)=>{
63 | browser.menus.create({
64 | id: commonLookup.actlist.copySelectedUrls + "-" + idx.toString(),
65 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedUrls").format(item.name),
66 | contexts: ["selection"]
67 | });
68 | });
69 | browser.menus.create({
70 | id: commonLookup.actlist.openSelectedUrls + "-0",
71 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"openSelectedUrls"),
72 | contexts: ["selection"]
73 | });
74 | browser.menus.create({
75 | id: "separator-2",
76 | type: "separator",
77 | contexts: ["selection"]
78 | });
79 | tlt.userTltSetting.imageUrlsCustomFormatList.forEach((item,idx)=>{
80 | browser.menus.create({
81 | id: commonLookup.actlist.copySelectedImageUrls + "-" + idx.toString(),
82 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedImageUrls").format(item.name),
83 | contexts: ["selection"]
84 | });
85 | });
86 | browser.menus.create({
87 | id: commonLookup.actlist.showSelectedImages + "-0",
88 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"showSelectedImages"),
89 | contexts: ["selection"]
90 | });
91 | browser.menus.create({
92 | id: commonLookup.actlist.copyPagePuretext + "-0",
93 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPagePuretext"),
94 | contexts: ["page"]
95 | });
96 | browser.menus.create({
97 | id: commonLookup.actlist.copyPageHtmltext + "-0",
98 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPageHtmltext"),
99 | contexts: ["page"]
100 | });
101 | browser.menus.create({
102 | id: "separator-3",
103 | type: "separator",
104 | contexts: ["page"]
105 | });
106 | tlt.userTltSetting.urlsCustomFormatList.forEach((item,idx)=>{
107 | browser.menus.create({
108 | id: commonLookup.actlist.copyPageUrls + "-" + idx.toString(),
109 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPageUrls").format(item.name),
110 | contexts: ["page"]
111 | });
112 | });
113 | browser.menus.create({
114 | id: commonLookup.actlist.openPageUrls + "-0",
115 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"openPageUrls"),
116 | contexts: ["page"]
117 | });
118 | browser.menus.create({
119 | id: "separator-4",
120 | type: "separator",
121 | contexts: ["page"]
122 | });
123 | tlt.userTltSetting.imageUrlsCustomFormatList.forEach((item,idx)=>{
124 | browser.menus.create({
125 | id: commonLookup.actlist.copyPageImageUrls + "-" + idx.toString(),
126 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPageImageUrls").format(item.name),
127 | contexts: ["page"]
128 | });
129 | });
130 | browser.menus.create({
131 | id: commonLookup.actlist.showPageImages + "-0",
132 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"showPageImages"),
133 | contexts: ["page"]
134 | });
135 | browser.menus.create({
136 | id: "separator-5",
137 | type: "separator",
138 | contexts: ["selection"]
139 | });
140 | tlt.userTltSetting.aObjectsCustomFormatList.forEach((item,idx)=>{
141 | browser.menus.create({
142 | id: commonLookup.actlist.copySelectedAObjectsInfo + "-" + idx.toString(),
143 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedAObjectsInfo").format(item.name),
144 | contexts: ["selection"]
145 | });
146 | });
147 | tlt.userTltSetting.imageUrlsCustomFormatList.forEach((item,idx)=>{
148 | browser.menus.create({
149 | id: commonLookup.actlist.copySelectedImgObjectsInfo + "-" + idx.toString(),
150 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copySelectedImgObjectsInfo").format(item.name),
151 | contexts: ["selection"]
152 | });
153 | });
154 | browser.menus.create({
155 | id: "separator-6",
156 | type: "separator",
157 | contexts: ["page"]
158 | });
159 | tlt.userTltSetting.aObjectsCustomFormatList.forEach((item,idx)=>{
160 | browser.menus.create({
161 | id: commonLookup.actlist.copyPageAObjectsInfo + "-" + idx.toString(),
162 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPageAObjectsInfo").format(item.name),
163 | contexts: ["page"]
164 | });
165 | });
166 | tlt.userTltSetting.imageUrlsCustomFormatList.forEach((item,idx)=>{
167 | browser.menus.create({
168 | id: commonLookup.actlist.copyPageImgObjectsInfo + "-" + idx.toString(),
169 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyPageImgObjectsInfo").format(item.name),
170 | contexts: ["page"]
171 | });
172 | });
173 | browser.menus.create({
174 | id: commonLookup.actlist.copyTabName + "-0",
175 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyTabName"),
176 | contexts: ["tab"]
177 | });
178 | browser.menus.create({
179 | id: commonLookup.actlist.copyTabUrl + "-0",
180 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyTabUrl"),
181 | contexts: ["tab"]
182 | });
183 | tlt.userTltSetting.tabCustomFormatList.forEach((item,idx)=>{
184 | browser.menus.create({
185 | id: commonLookup.actlist.copyTabFormatText + "-" + idx.toString(),
186 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyTabFormatText").format(item.name),
187 | contexts: ["tab"]
188 | });
189 | });
190 | browser.menus.create({
191 | id: "separator-7",
192 | type: "separator",
193 | contexts: ["tab"]
194 | });
195 | tlt.userTltSetting.tabsinfoCustomFormatList.forEach((item,idx)=>{
196 | browser.menus.create({
197 | id: commonLookup.actlist.copyAllTabsInfo + "-" + idx.toString(),
198 | title: commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"copyAllTabsInfo").format(item.name),
199 | contexts: ["tab"]
200 | });
201 | });
202 | });
203 | }
204 | function tabActivated(tab)
205 | {
206 | //Menus rebuild
207 | browser.menus.removeAll().then(()=>{
208 | browser.browserAction.disable(tab.tabId);
209 | browser.tabs.get(tab.tabId).then(menuCombine);
210 | });
211 | }
212 | function tabUpdated(tabid, info, tab)
213 | {
214 | //Menus rebuild
215 | if (tab.status=="complete")
216 | browser.menus.removeAll().then(()=>{
217 | browser.browserAction.disable(tab.id);
218 | menuCombine(tab);
219 | });
220 | }
221 |
222 | //Main Methods
223 | browser.menus.onClicked.addListener((info, tab) => {
224 | browser.tabs.query({
225 | currentWindow: true,
226 | active: true
227 | }).then((acttabs) => {
228 | let acttab = acttabs[0];
229 | let actinfo = info.menuItemId.split("-");
230 | let actid = actinfo[0];
231 | let actidx = Number(actinfo[1]);
232 | switch (actid) {
233 | case commonLookup.actlist.copySelectedPuretext:
234 | case commonLookup.actlist.copyPagePuretext:
235 | case commonLookup.actlist.copySelectedHtmltext:
236 | case commonLookup.actlist.copyPageHtmltext:
237 | case commonLookup.actlist.copySelectedUrls:
238 | case commonLookup.actlist.copyPageUrls:
239 | case commonLookup.actlist.openSelectedUrls:
240 | case commonLookup.actlist.openPageUrls:
241 | case commonLookup.actlist.copySelectedImageUrls:
242 | case commonLookup.actlist.copyPageImageUrls:
243 | case commonLookup.actlist.copySelectedAObjectsInfo:
244 | case commonLookup.actlist.copyPageAObjectsInfo:
245 | case commonLookup.actlist.copySelectedImgObjectsInfo:
246 | case commonLookup.actlist.copyPageImgObjectsInfo:
247 | case commonLookup.actlist.showSelectedImages:
248 | case commonLookup.actlist.showPageImages:
249 | executeCommand(acttab, {
250 | cmd: actid,
251 | idx: actidx
252 | });
253 | break;
254 | case commonLookup.actlist.copyLinkName:
255 | case commonLookup.actlist.copyLinkUrl:
256 | case commonLookup.actlist.copyLinkFormatText:
257 | executeCommand(acttab, {
258 | cmd: actid,
259 | data: {
260 | name: info.linkText,
261 | url: info.linkUrl
262 | },
263 | idx: actidx
264 | });
265 | break;
266 | case commonLookup.actlist.copyTabName:
267 | case commonLookup.actlist.copyTabUrl:
268 | case commonLookup.actlist.copyTabFormatText:
269 | executeCommand(acttab, {
270 | cmd: actid,
271 | data: {
272 | name: tab.title,
273 | url: tab.url
274 | },
275 | idx: actidx
276 | });
277 | break;
278 | case commonLookup.actlist.copyAllTabsInfo:
279 | let tabsInfo=[];
280 | browser.tabs.query({currentWindow:true}).then((ti)=>{
281 | ti.forEach((t)=>{
282 | tabsInfo.push({name:t.title,url:t.url});
283 | });
284 | executeCommand(acttab, {
285 | cmd: actid,
286 | data: tabsInfo,
287 | idx: actidx
288 | });
289 | });
290 | break;
291 | case commonLookup.actlist.copyImageUrl:
292 | executeCommand(acttab, {
293 | cmd: actid,
294 | data: {
295 | url: info.srcUrl
296 | },
297 | idx: actidx
298 | });
299 | break;
300 | case commonLookup.actlist.showImage:
301 | commonLookup.getUserTltSetting().then((tlt) => {
302 | let data = [info.srcUrl];
303 | let cmd = commonLookup.actlist.serverOpenTabs;
304 | if (tlt.userTltSetting.openOneImageDirectly === false) {
305 | cmd = commonLookup.actlist.serverShowImages;
306 | }
307 | serverAction({
308 | cmd: cmd,
309 | data: data,
310 | idx: actidx
311 | });
312 | });
313 | break;
314 | default:
315 | console.log("no use");
316 | }
317 | });
318 | });
319 | browser.browserAction.onClicked.addListener((tab) => {
320 | executeCommand(tab, {
321 | cmd: commonLookup.actlist.toolbarButtonAction
322 | });
323 | });
324 | browser.commands.onCommand.addListener((command) => {
325 | browser.tabs.query({
326 | currentWindow: true,
327 | active: true
328 | }).then((acttabs) => {
329 | let acttab = acttabs[0];
330 | executeCommand(acttab, {
331 | cmd: commonLookup.actlist.keyboardShortcutAction
332 | });
333 | });
334 | });
335 |
336 | //Common Method
337 | //execute command on page
338 | function executeCommand(tab, msg) {
339 | browser.tabs.sendMessage(tab.id, msg)
340 | .then(() => {
341 | console.log("Command executed.");
342 | })
343 | .catch((errmsg) => {
344 | console.error(`Command failed: ${errmsg}`);
345 | });
346 | }
347 |
348 | //execute command on background
349 | function serverAction(msg) {
350 | switch (msg.cmd) {
351 | case commonLookup.actlist.serverOpenTabs:
352 | msg.data.forEach((u) => {
353 | browser.tabs.create({
354 | url: u
355 | });
356 | });
357 | break;
358 | case commonLookup.actlist.serverShowImages:
359 | browser.tabs.create({
360 | url: "imglist.html"
361 | }).then((tab) => {
362 | browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
363 | if (tabId == tab.id) {
364 | executeCommand(tab, msg);
365 | }
366 | });
367 | });
368 | break;
369 | default:
370 | console.log("no use");
371 | }
372 | }
373 |
374 | //tabs listener
375 | browser.tabs.onActivated.addListener(tabActivated);
376 | browser.tabs.onUpdated.addListener(tabUpdated);
377 |
378 | //background listener
379 | browser.runtime.onMessage.addListener(serverAction);
--------------------------------------------------------------------------------
/TextLinkyTool/content.js:
--------------------------------------------------------------------------------
1 | //copy text to clipboard
2 | function copyToClipboard(text) {
3 | function oncopy(event) {
4 | document.removeEventListener("copy", oncopy, true);
5 | event.stopImmediatePropagation();
6 | event.preventDefault();
7 | event.clipboardData.setData("text/plain", text);
8 | }
9 | document.addEventListener("copy", oncopy, true);
10 | document.execCommand("copy");
11 | }
12 |
13 | //get selected context text
14 | function getSelectedText() {
15 | let txt = "";
16 | let selection = window.getSelection();
17 | if (selection !== null) {
18 | txt = selection.toString();
19 | }
20 | if (txt === "" && document.activeElement.value !== undefined) {
21 | txt = document.activeElement.value.substring(document.activeElement.selectionStart, document.activeElement.selectionEnd);
22 | }
23 | if (txt === "") {
24 | txt = document.body.innerText;
25 | }
26 | return txt;
27 | }
28 |
29 | //get selected context objects
30 | function getSelectedObject() {
31 | let body = document.body;
32 | let actelement = document.activeElement;
33 | let selection = window.getSelection();
34 | if (selection === null || selection.rangeCount === 0 || selection.toString() === "") {
35 | if (actelement.value === undefined) {
36 | return body;
37 | }
38 | body = document.createElement("div");
39 | body.appendChild(actelement.cloneNode(true));
40 | } else {
41 | body = document.createElement("div");
42 | body.appendChild(selection.getRangeAt(0).cloneContents().cloneNode(true));
43 | }
44 | return body;
45 | }
46 |
47 | //copy selected context to pure text
48 | function copySelectedPureText() {
49 | commonLookup.getUserTltSetting().then((tlt) => {
50 | let txt = getSelectedText();
51 | if (tlt.userTltSetting.puretextFormat.delAroundSpace === true) {
52 | txt = txt.replace(new RegExp(/^\s*|\s*$/,"gu"), "");
53 | }
54 | if (tlt.userTltSetting.puretextFormat.delInvisibleSpace === true) {
55 | txt = txt.replace(new RegExp(/[\r\f\v]/,"gu"), "");
56 | }
57 | if (tlt.userTltSetting.puretextFormat.convertQuotation === true) {
58 | txt = txt.replace(new RegExp(/[“”〝〞„〃]/,"gu"), '"');
59 | }
60 | if (tlt.userTltSetting.puretextFormat.convertApostrophe === true) {
61 | txt = txt.replace(new RegExp(/[‵′‘’]/,"gu"), "'");
62 | }
63 | if (tlt.userTltSetting.puretextFormat.convertDash === true) {
64 | txt = txt.replace(new RegExp(/[╴-─‒–—―]/,"gu"), "-");
65 | }
66 | if (tlt.userTltSetting.puretextFormat.convertSpace === true) {
67 | txt = txt.replace(new RegExp(/[ ]/,"gu"), " ");
68 | }
69 | if (tlt.userTltSetting.puretextFormat.mergeNewline === true) {
70 | txt = txt.replace(new RegExp(/[\r]+/,"gu"), "").replace(new RegExp(/\s*\n\s*\n\s*/,"g"), "\n");
71 | }
72 | if (tlt.userTltSetting.puretextFormat.mergeSpace === true) {
73 | txt = txt.replace(new RegExp(/[ ]+/,"gu"), " ");
74 | }
75 | if (tlt.userTltSetting.puretextFormat.mergeFullwidthSpace === true) {
76 | txt = txt.replace(new RegExp(/[ ]+/,"gu"), " ");
77 | }
78 | if (tlt.userTltSetting.puretextFormat.mergeTabulation === true) {
79 | txt = txt.replace(new RegExp(/[\t]+/,"gu"), "\t");
80 | }
81 | if (tlt.userTltSetting.puretextFormat.mergeAllTypeSpace === true) {
82 | txt = txt.replace(new RegExp(/[\r\f\v]/,"gu"), "").replace(new RegExp(/[ \t]+/,"gu"), " ");
83 | }
84 | copyToClipboard(txt);
85 | });
86 | }
87 |
88 | //copy selected context to HTML text
89 | function copySelectedHtmlText() {
90 | commonLookup.getUserTltSetting().then((tlt) => {
91 | let txt = "";
92 | if (!tlt.userTltSetting.htmltextFormatWithoutTag) {
93 | txt = getSelectedObject().innerHTML;
94 | }
95 | else {
96 | txt = getSelectedObject().innerText;
97 | }
98 | copyToClipboard(txt);
99 | });
100 | }
101 |
102 | //analyze selected context link URLs
103 | function getSelectedUrls(fixquot,blobtolocal) {
104 | let body = getSelectedObject().innerHTML + "\n" + getSelectedText();
105 | let regex1 = new RegExp(/
]*?\s+)?src=(["'])(.*?)\1/,"gi");
106 | let imglist = body.match(regex1);
107 | if (imglist === null) {
108 | imglist = [];
109 | } else {
110 | imglist = imglist.map((s) => {
111 | return s.replace(new RegExp(/
]*?\s+)?src=(["'])/,"i"), "").replace(new RegExp(/["']$/,"i"), "");
112 | });
113 | body = body.replace(regex1, "");
114 | }
115 | let regex4 = new RegExp(/background\-image\:\s*url\(((\"\;)|\"|\')(.*?)((\"\;)|\"|\')\)/,"gi");
116 | let cssbglist = body.match(regex4);
117 | if (cssbglist === null) {
118 | cssbglist = [];
119 | } else {
120 | cssbglist = cssbglist.map((s) => {
121 | return s.replace(new RegExp(/background\-image\:\ url\(((\"\;)|\"|\')/,"i"), "").replace(new RegExp(/((\"\;)|\"|\')\)$/,"i"), "");
122 | });
123 | body = body.replace(regex4, "");
124 | }
125 | let regex5 = new RegExp(/\s+background=[\"\'](.*?)[\"\']/,"gi");
126 | let attbglist = body.match(regex5);
127 | if (attbglist === null) {
128 | attbglist = [];
129 | } else {
130 | attbglist = attbglist.map((s) => {
131 | return s.replace(new RegExp(/\s+background=[\"\']/,"i"), "").replace(new RegExp(/["']$/,"i"), "");
132 | });
133 | body = body.replace(regex5, "");
134 | }
135 | let regex2 = new RegExp(/]*?\s+)?href=(["'])(.*?)\1/,"gi");
136 | let alist = body.match(regex2);
137 | if (alist === null) {
138 | alist = [];
139 | } else {
140 | alist = alist.map((s) => {
141 | return s.replace(new RegExp(/]*?\s+)?href=(["'])/,"i"), "").replace(new RegExp(/["']$/,"i"), "");
142 | });
143 | body = body.replace(regex2, "");
144 | }
145 | let regex3 = new RegExp(/((ftp|https?):\/\/(www\.)?)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)/,"gi");
146 | let matches = body.match(regex3);
147 | if (matches === null) {
148 | matches = [];
149 | }
150 | let urls = imglist.concat(cssbglist).concat(attbglist).concat(alist).concat(matches).map((h) => {
151 | let u = getAbsolutePath(h);
152 | if (fixquot === true) { u = u.replace(new RegExp(/\"*$/,"i"), ""); }
153 | return u;
154 | }).filter((value, index, self) => {
155 | return self.indexOf(value) === index;
156 | });
157 | return urls;
158 | }
159 |
160 | //copy link URLs
161 | function copySelectedUrls(idx) {
162 | commonLookup.getUserTltSetting().then((tlt) => {
163 | let i = 0;
164 | let formatRule = tlt.userTltSetting.urlsCustomFormatList[idx].data.getFormatRule();
165 | let formatText = '';
166 | getSelectedUrls(tlt.userTltSetting.fixUrlQuotEnd,tlt.userTltSetting.blobUrlToLocal).forEach((url) => {
167 | i++;
168 | let u=new URL(url);
169 | formatText += formatRule.format("[[name]]", url, "\n", "\t", i.toString(),u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
170 | });
171 | copyToClipboard(formatText);
172 | });
173 | }
174 |
175 | //open link URLs to browser tabs
176 | function openSelectedUrls() {
177 | commonLookup.getUserTltSetting().then((tlt) => {
178 | let urls = getSelectedUrls(tlt.userTltSetting.fixUrlQuotEnd,tlt.userTltSetting.blobUrlToLocal);
179 | let limit = Number(tlt.userTltSetting.openPagesLimit);
180 | if (urls.length > limit) {
181 | urls = urls.slice(0, limit);
182 | alert(commonLookup.getMessage(tlt.userTltSetting.locale,tlt.userTltSetting.localeData,"tabsLimitAlert").format(tlt.userTltSetting.openPagesLimit));
183 | }
184 | browser.runtime.sendMessage({
185 | cmd: commonLookup.actlist.serverOpenTabs,
186 | data: urls
187 | });
188 | });
189 | }
190 |
191 | //filter images URLs
192 | function getSelectedImageUrls(fixquot,blobtolocal) {
193 | let body = getSelectedObject().innerHTML;
194 | let regex1 = new RegExp(/
]*?\s+)?src=(["'])(.*?)\1/,"gi");
195 | let imglist1 = body.match(regex1);
196 | if (imglist1 === null) {
197 | imglist1 = [];
198 | } else {
199 | imglist1 = imglist1.map((s) => {
200 | return s.replace(new RegExp(/
]*?\s+)?src=(["'])/,"i"), "").replace(new RegExp(/["']$/,"i"), "");
201 | });
202 | body = body.replace(regex1, "");
203 | }
204 | let regex4 = new RegExp(/background\-image\:\s*url\(((\"\;)|\"|\')(.*?)((\"\;)|\"|\')\)/,"gi");
205 | let cssbglist = body.match(regex4);
206 | if (cssbglist === null) {
207 | cssbglist = [];
208 | } else {
209 | cssbglist = cssbglist.map((s) => {
210 | return s.replace(new RegExp(/background\-image\:\ url\(((\"\;)|\"|\')/,"i"), "").replace(new RegExp(/((\"\;)|\"|\')\)$/,"i"), "");
211 | });
212 | body = body.replace(regex4, "");
213 | }
214 | let regex5 = new RegExp(/\s+background=[\"\'](.*?)[\"\']/,"gi");
215 | let attbglist = body.match(regex5);
216 | if (attbglist === null) {
217 | attbglist = [];
218 | } else {
219 | attbglist = attbglist.map((s) => {
220 | return s.replace(new RegExp(/\s+background=[\"\']/,"i"), "").replace(new RegExp(/["']$/,"i"), "");
221 | });
222 | body = body.replace(regex5, "");
223 | }
224 | let regex = new RegExp(/\.(bmp|gif|jpe?g|png|tif?f|svg|webp)(\?.*)?$/,"gi");
225 | let imglist2 = getSelectedUrls(fixquot,blobtolocal).filter((value, index, self) => {
226 | return regex.test(value);
227 | });
228 | let urls = imglist1.concat(cssbglist).concat(attbglist).concat(imglist2).map((h) => {
229 | let u = getAbsolutePath(h);
230 | if (fixquot === true) { u = u.replace(new RegExp(/\"*$/,"i"), ""); }
231 | return u;
232 | }).filter((value, index, self) => {
233 | return self.indexOf(value) === index;
234 | });
235 | let blobregex = new RegExp(/^blob:/,"i");
236 | if (blobtolocal === true) {
237 | urls = urls.map((u)=>{
238 | if (blobregex.test(u)) { u = getImageToLocal(u); }
239 | return u;
240 | }).filter((value, index, self) => {
241 | return self.indexOf(value) === index;
242 | });
243 | }
244 | return urls;
245 | }
246 |
247 | //get absolute path
248 | const getAbsolutePath = ((href)=>{
249 | const a = document.createElement("a");
250 | const parser = new DOMParser;
251 |
252 | return function _getAbsolutePath() {
253 | a.href = href;
254 | if (a.protocol == "blob:" || a.protocol == "data:") { return href; }
255 | let dom = parser.parseFromString("" + (a.protocol + "//" + a.host + a.pathname + a.search + a.hash), "text/html");
256 | return dom.body.textContent;
257 | }();
258 | });
259 |
260 | //get image to local
261 | const getImageToLocal = ((url) => {
262 | const canvas = document.createElement("canvas");
263 | const ctx = canvas.getContext("2d");
264 |
265 | return function _getImageToLocal() {
266 | let img=document.querySelector("img[src='" + url +"']");
267 | canvas.width = img.naturalWidth;
268 | canvas.height = img.naturalHeight;
269 | ctx.drawImage(img, 0, 0);
270 | return canvas.toDataURL();
271 | }();
272 | });
273 |
274 | //copy images link URLs
275 | function copySelectedImageUrls(idx) {
276 | commonLookup.getUserTltSetting().then((tlt) => {
277 | let i = 0;
278 | let formatRule = tlt.userTltSetting.imageUrlsCustomFormatList[idx].data.getFormatRule();
279 | let formatText = '';
280 | getSelectedImageUrls(tlt.userTltSetting.fixUrlQuotEnd,tlt.userTltSetting.blobUrlToLocal).forEach((url) => {
281 | i++;
282 | let u=new URL(url);
283 | formatText += formatRule.format("[[name]]", url, "\n", "\t", i.toString(),u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
284 | });
285 | copyToClipboard(formatText);
286 | });
287 | }
288 |
289 | //show images
290 | function showSelectedImages() {
291 | commonLookup.getUserTltSetting().then((tlt) => {
292 | let urls = getSelectedImageUrls(tlt.userTltSetting.fixUrlQuotEnd,tlt.userTltSetting.blobUrlToLocal);
293 | let title = document.title;
294 | let location = document.location.toString();
295 | browser.runtime.sendMessage({
296 | cmd: commonLookup.actlist.serverShowImages,
297 | data: {"urls":urls,"title":title,"location":location}
298 | });
299 | });
300 | }
301 |
302 | //copy Objects Info
303 | function copySelectedAObjectsInfo(idx) {
304 | commonLookup.getUserTltSetting().then((tlt) => {
305 | let i = 0;
306 | let formatRule = tlt.userTltSetting.aObjectsCustomFormatList[idx].data.getFormatRule();
307 | let formatText = '';
308 | getSelectedObject().querySelectorAll("a").forEach((obj) => {
309 | i++;
310 | let u=new URL(obj.href);
311 | formatText += formatRule.format(obj.innerHTML.toString(), obj.href, "\n", "\t", i.toString(),u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
312 | });
313 | copyToClipboard(formatText);
314 | });
315 | }
316 |
317 | //copy
Objects Info
318 | function copySelectedImgObjectsInfo(idx) {
319 | commonLookup.getUserTltSetting().then((tlt) => {
320 | let i = 0;
321 | let formatRule = tlt.userTltSetting.imgObjectsCustomFormatList[idx].data.getFormatRule();
322 | let formatText = '';
323 | getSelectedObject().querySelectorAll("img").forEach((obj) => {
324 | i++;
325 | let u=new URL(obj.src);
326 | formatText += formatRule.format(obj.alt, obj.src, "\n", "\t", i.toString(),u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
327 | });
328 | copyToClipboard(formatText);
329 | });
330 | }
331 |
332 | //copy link format text
333 | function copyLinkFormatText(name, url, idx) {
334 | commonLookup.getUserTltSetting().then((tlt) => {
335 | let formatRule = tlt.userTltSetting.linkCustomFormatList[idx].data.getFormatRule();
336 | let u=new URL(url);
337 | let formatText = formatRule.format(name, url, "\n", "\t", "[[index]]",u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
338 | copyToClipboard(formatText);
339 | });
340 | }
341 |
342 | //copy tab format text
343 | function copyTabFormatText(name, url, idx) {
344 | commonLookup.getUserTltSetting().then((tlt) => {
345 | let formatRule = tlt.userTltSetting.tabCustomFormatList[idx].data.getFormatRule();
346 | let u=new URL(url);
347 | let formatText = formatRule.format(name, url, "\n", "\t", "[[index]]",u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
348 | copyToClipboard(formatText);
349 | });
350 | }
351 |
352 | //copy all tabs info
353 | function copyAllTabsInfo(tabsInfo, idx) {
354 | commonLookup.getUserTltSetting().then((tlt) => {
355 | let i = 0;
356 | let formatRule = tlt.userTltSetting.tabsinfoCustomFormatList[idx].data.getFormatRule();
357 | let formatText = "";
358 | tabsInfo.forEach((ti) => {
359 | i++;
360 | let u=new URL(ti.url);
361 | formatText += formatRule.format(ti.name, ti.url, "\n", "\t", i.toString(),u.protocol,u.host,u.hostname,u.port,u.pathname,u.search,u.hash,u.origin,u.pathname+u.search+u.hash);
362 | });
363 | copyToClipboard(formatText);
364 | });
365 | }
366 |
367 | //toolbar button action
368 | function toolbarButtonAction() {
369 | commonLookup.getUserTltSetting().then((tlt) => {
370 | executeCommand({
371 | cmd: tlt.userTltSetting.toolbarButtonAction,
372 | idx: tlt.userTltSetting.toolbarButtonActionIdx
373 | });
374 | });
375 | }
376 |
377 |
378 | //keyboard shortcut action
379 | function keyboardShortcutAction() {
380 | commonLookup.getUserTltSetting().then((tlt) => {
381 | executeCommand({
382 | cmd: tlt.userTltSetting.keyboardShortcutAction,
383 | idx: tlt.userTltSetting.keyboardShortcutActionIdx
384 | });
385 | });
386 | }
387 |
388 | //execute command
389 | function executeCommand(msg) {
390 | if (msg.cmd === commonLookup.actlist.serverShowImages) {
391 | return;
392 | }
393 | switch (msg.cmd) {
394 | case commonLookup.actlist.copyPagePuretext:
395 | getTopWindow();
396 | case commonLookup.actlist.copySelectedPuretext:
397 | copySelectedPureText();
398 | break;
399 | case commonLookup.actlist.copyPageHtmltext:
400 | getTopWindow();
401 | case commonLookup.actlist.copySelectedHtmltext:
402 | copySelectedHtmlText();
403 | break;
404 | case commonLookup.actlist.copyPageUrls:
405 | getTopWindow();
406 | case commonLookup.actlist.copySelectedUrls:
407 | copySelectedUrls(msg.idx);
408 | break;
409 | case commonLookup.actlist.openPageUrls:
410 | getTopWindow();
411 | case commonLookup.actlist.openSelectedUrls:
412 | openSelectedUrls();
413 | break;
414 | case commonLookup.actlist.copyPageImageUrls:
415 | getTopWindow();
416 | case commonLookup.actlist.copySelectedImageUrls:
417 | copySelectedImageUrls(msg.idx);
418 | break;
419 | case commonLookup.actlist.showPageImages:
420 | getTopWindow();
421 | case commonLookup.actlist.showSelectedImages:
422 | showSelectedImages();
423 | break;
424 | case commonLookup.actlist.copyLinkName:
425 | case commonLookup.actlist.copyTabName:
426 | copyToClipboard(msg.data.name);
427 | break;
428 | case commonLookup.actlist.copyLinkUrl:
429 | case commonLookup.actlist.copyTabUrl:
430 | case commonLookup.actlist.copyImageUrl:
431 | copyToClipboard(msg.data.url);
432 | break;
433 | case commonLookup.actlist.copyLinkFormatText:
434 | copyLinkFormatText(msg.data.name, msg.data.url, msg.idx);
435 | break;
436 | case commonLookup.actlist.copyTabFormatText:
437 | copyTabFormatText(msg.data.name, msg.data.url, msg.idx);
438 | break;
439 | case commonLookup.actlist.copyPageAObjectsInfo:
440 | getTopWindow();
441 | case commonLookup.actlist.copySelectedAObjectsInfo:
442 | copySelectedAObjectsInfo(msg.idx);
443 | break;
444 | case commonLookup.actlist.copyPageImgObjectsInfo:
445 | getTopWindow();
446 | case commonLookup.actlist.copySelectedImgObjectsInfo:
447 | copySelectedImgObjectsInfo(msg.idx);
448 | break;
449 | case commonLookup.actlist.copyAllTabsInfo:
450 | copyAllTabsInfo(msg.data, msg.idx);
451 | break;
452 | case commonLookup.actlist.toolbarButtonAction:
453 | toolbarButtonAction();
454 | break;
455 | case commonLookup.actlist.keyboardShortcutAction:
456 | keyboardShortcutAction();
457 | break;
458 | default:
459 | console.log("no use");
460 | }
461 | }
462 |
463 | //get top window
464 | function getTopWindow()
465 | {
466 | let topwindow=window.self;
467 | while (window.top!=topwindow) { topwindow=window.top; }
468 | topwindow.document.querySelectorAll("input,textarea").forEach((s)=>{s.blur();});
469 | }
470 |
471 | //page listener
472 | browser.runtime.onMessage.addListener(executeCommand);
--------------------------------------------------------------------------------