From 1921d0e626fb2e95d3ab43d3f16ec486dd311137 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 3 Jun 2024 22:50:19 +0800 Subject: [PATCH] refactor: port to manifest v3 --- background.js | 11 ----------- common_content_script.js | 5 ++--- icon.jpg | Bin 0 -> 1965 bytes icon.png | Bin 0 -> 6795 bytes manifest.json | 27 +++++++++++++-------------- popup.html | 7 +++---- popup.js | 6 ++++-- 7 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 background.js create mode 100644 icon.jpg create mode 100644 icon.png diff --git a/background.js b/background.js deleted file mode 100644 index ad1c29a..0000000 --- a/background.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -chrome.browserAction.onClicked.addListener(function(callback) { - //chrome.declarativeContent.ShowPageAction(); -}); - -chrome.runtime.onInstalled.addListener(function() { -// chrome.storage.sync.set({color: '#3aa757'}, function() { -// console.log("The color is green."); -// }); -}); diff --git a/common_content_script.js b/common_content_script.js index 332c840..c531d7e 100644 --- a/common_content_script.js +++ b/common_content_script.js @@ -17,8 +17,7 @@ function twitterXPath(nth, sendResponse) { sendResponse({dataType: 'urlList', urlList: arr, source: window.location.href}); } -chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { - +chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.action == "requestPics") { twitterXPath(1, sendResponse); } else if (request.action == "requestPics2") { @@ -28,6 +27,6 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { } else if (request.action == "requestPics4") { twitterXPath(4, sendResponse); } else { - sendResponse({}); // Send nothing.. + sendResponse({dataType: 'test'}); // Send nothing.. } }); diff --git a/icon.jpg b/icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cb9c3ef3ae7a35fd92c2a8d51b89ba3169fafe94 GIT binary patch literal 1965 zcmbV}dsNbC8pnSK3Zh1Mt*OZ=b(*}y<~7sem`mQqbu-aW%XO?YkxWg+D{F3fU$=3v zRr5G%mN(Yb1XC2I(80@^)~bX`1f}L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r{^o!hxaW?2o|t_i zYL|X^tq=A1O`DqnWAnM`ri*j`R9hW>3|T{b>gJ_%1>QZ1sbeP%QD)y#T%}$+#nxs{ fr$d(vd_{)yBDB?2JOP1(oCMC}jK^}ZYW}|fNyn4Q literal 0 HcmV?d00001 diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f933d046ef34421aaff288f14018371fb46a6a52 GIT binary patch literal 6795 zcmV;68g%7}P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&8X!qTK~!i%m6~@{ zmG{2pS#xtwo1EmHb7D-?*fq8&2E{Id0s?}fVnJ!UcY2p1h=^jrO5gM%B7MUyY(R}A zG4>c^ImXlOnzLrjtTpr3oi#JhJim9-a_(98-udHM@2>Cue%^0?!L7=vgpheq?UF-- zYP%Yh4mB$HyxgfqDRpH?C8=~sA*p;wCaH2zC8@%x7?n&?`B1c^(&3-#%CKyb#$Jya z|6a92<<&37C(L6?>d^iGEMj|i{Qbl70h&aLIlZ=6sN)RrPa-L8? zh#!_tJTCFvr3(I-&=}B!WITuKA_#~w8YAR7mjF>rz)&s_LX3m(b3AYL;3&vYlnbPC zNC_bUA~Xgv1~cZBa;IukV^@B{@M_1Xc=G>qjLGHo zD7aM+La6fZfJ}xFS44pP#Kogt7&nrJnEyW{K40aOOB%Zv5`c}*h3qk-FfITIWDuzY{cplaJQuHikjlG$C zJri}7bbc-s=7CfKrx1v6_BhIfDu+QjxA=`RdZc_XhH@G20-4Ceu`m`#vm=Tgq({aR zcr;8VdqSv8JRdQloc%?pdXORFG@-m(fo6Lm8hcXE+?kF(#|d;>@=;wAi%S<3ICnM% z=T1kX=tMY5E+}yE3a@xWJg!;t&^mAwwcVNgel}|Q6H#g5IR_IYm@CYqvLSwUm^KZ| zr4W)}CgqMRw}ic8xg}%OnglThG6o^8PW7-sf~gsbs9QQ>}A`U)}N zD8jXY4Ak{7Bzq0GdMg8sw^LE(&`B_t90ZwUu&XS)iis<7_`2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io_%$s9kRAH~l z)pH`&9wKne-vOZ}K$NKNS4i)P+%b2kFknkZUrRh3HE}q+%#E{?2X1JV;IV$OG?u(l zPG^WQgb4LUHiMzW*BDN(WqgegKPbjPKEv1A`51}yK!?r)bxKc;`0JVQ-YDYOQNZyd zow1*12*VM1FbX-ENC_{(Nh-VaihdumwUj=b<(Ci=NWXRz!llU|QrIzXDms-^!tj98z}JQqaO&6Kn%ooR99P7sa*BQAD0@R1 zx6hDO^H3Cb7)Mp1IL=U#2F6hkktccdn7G?Q5Rn6l(Ij_))Dxsh+(so#jYZDTQli2t zN4Z4?(LkF!jj(j3;#PYmBER@YSlJwJ$8Ev`-EzFt&ch3Wyp?|{CA~=UH!)Ksje)!% zd3Xs6JMNWXD^`P!V}(~e~dy?xYWS~NP#ho5MufbP|ju+dm3)`W+7?&JQQr5jT^CBai1fH7}eit=CS+| zKtQm6xM1idN`U+z9|KuH_*Gnq*Wr518knOt;EKW*#oSGVM~dSk;lF$u6ak(%6?e!L zUi5?rt>bYAafG`{nqeQ(O$XrC*cX9@{s>m3NR(R-OaC@eX^Td+jX*Y+;pN@z_|o6+ zD2t9>)1uQ62YXKv$`brxTK+58ICtGQtixljwr@BTzT$}TBggjF5!3J|B?rcc-*U8P z?#MsJ3wr8_Y#N^Fm*87|=Z1a@_xUYcv^L?A!cV%9cY;^H$aD~~d%fVd^kbAHMjmAj<=HO2X?j`ifyQq)w zXBCq^<|C<>ywJ?Xea>9>IiA>*8@Zc!qcVCkN>xD;ND-@)NaSpJ2)yQhh?M<4$c_p` tvGD-1VuEl?9fpF~{m4t$g;@Cp{6C*kMMT2ABhdf=002ovPDHLkV1mKU)OY{@ literal 0 HcmV?d00001 diff --git a/manifest.json b/manifest.json index ef50511..2e026a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,22 +1,21 @@ { + "manifest_version": 3, "name": "Download The Pics (WebExtension Client)", - "version": "1.0", - "manifest_version": 2, "description": "Download The Pics WebExtension Client. You also need the local daemon process to make this extension works", - "background": { - "scripts": ["background.js"] + "version": "2.0", + "icons": { + "48": "icon.png" }, - "browser_action": { - "default_popup": "popup.html" + "permissions": ["activeTab", "declarativeContent"], + "action": { + "default_popup": "popup.html", + "default_icon": "icon.png" }, "content_scripts": [ - { - "matches": [""], - "run_at": "document_start", - "js": ["common_content_script.js"] - } - ], - "permissions": [ - "activeTab", "declarativeContent" + { + "matches": [""], + "run_at": "document_start", + "js": ["common_content_script.js"] + } ] } diff --git a/popup.html b/popup.html index 3e45c56..a184682 100644 --- a/popup.html +++ b/popup.html @@ -11,10 +11,9 @@ -
- - - + + + diff --git a/popup.js b/popup.js index 694ab62..3841928 100644 --- a/popup.js +++ b/popup.js @@ -9,9 +9,9 @@ let download4Btn = document.getElementById('download4'); // }); function sendActionAndResponse(actionStr) { - chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { // Send a request to the content script. - chrome.tabs.sendRequest(tab.id, {action: actionStr}, function(response) { + chrome.tabs.sendMessage(tabs[0].id, {action: actionStr}, (response) => { console.log(response); if (response.dataType == "urlList") { const data = new URLSearchParams(); @@ -24,6 +24,8 @@ function sendActionAndResponse(actionStr) { }).then(data => { console.log(data); }); + } else { + console.log(response.dataType) } }); });