在这里,我将提供所有代码。这非常简单,一切工作都很好,直到明天安装后看到我的5个扩展,从今天开始“此扩展可能已损坏。”
Manifest.json
{
"background": {
"page": "html/background.html"
},
"browser_action": {
"default_icon": "images/48x48.png",
"default_title": "SaveTheVideo.net"
},
"content_scripts": [ {
"js": [ "js/contentscript.js" ],
"matches": [ "https://tiktok.com/*", "http://tiktok.com/*", "http://www.tiktok.com/*", "https://www.tiktok.com/*" ],
"run_at": "document_start"
} ],
"default_locale": "en",
"description": "__MSG_description__",
"icons": {
"128": "images/128x128.png",
"16": "images/16x16.png",
"48": "images/48x48.png"
},
"manifest_version": 2,
"name": "__MSG_name__",
"offline_enabled": true,
"permissions": [ "tabs" ],
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "1.0.1"
}
background.js
window.tabsData = {};
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
// use `url` here inside the callback because it's asynchronous!
});
function newTabUrl(tabId, tabUrl){
let youtubeVideoId = tabUrl.match(/(?:(?:http|https):\/\/)?(?:www.)?tiktok.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-]*)?/);
if(youtubeVideoId === null){
chrome.browserAction.setIcon({tabId: tabId, path: "../images/48x48.png"});
if (window.tabsData[tabId]) {
delete window.tabsData[tabId];
}
return false;
}
window.tabsData[tabId] = youtubeVideoId[2];
chrome.browserAction.setIcon({tabId: tabId, path: "../images/48x48.png"});
}
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.url) {
newTabUrl(tabId,changeInfo.url);
}
});
chrome.tabs.onRemoved.addListener(function (tabId) {
if (window.tabsData[tabId]) {
delete window.tabsData[tabId];
}
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
switch (request.message) {
case "new-tab-url":
newTabUrl(sender.tab.id, sender.tab.url);
break;
}
});
chrome.browserAction.onClicked.addListener(function(activeTab)
{
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
newUrl = "https://savethevideo.net/#url="+url;
chrome.tabs.create({ url: newUrl });
// use `url` here inside the callback because it's asynchronous!
});
});
chrome.runtime.onInstalled.addListener(function() {
alert('Thanks for installing our extension, now you will be forwarded to our video where you will find detailed instruction on how to use this extension.');
chrome.tabs.create({
url: 'https://youtu.be/wvEiZEvdtT0',
active: true
});
return false;
});
现在,这是我的contentscript.js
chrome.runtime.sendMessage({message: 'new-tab-url'});
这是我的background.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Background Page</title>
<script type="text/javascript" src="../js/background.js"></script>
</head>
<body>
</body>
</html>
我还有三张尺寸为128x128、16x16和48x48的图像。
下面是我的扩展程序之一,已损坏。其他所有代码都具有相同的代码。
https://chrome.google.com/webstore/detail/downloader-for-instagram/dakdkhilibcpjndpgkimipmejepneklm
他们所做的是,他们将其与网站的有效标签网址一起转发,以便下载视频。