このリンクで https://developer.mozilla.org/en-US/Add-ons/WebExtensions
Mozilla が現在、最小限の変更で Firefox 用の Chrome 拡張機能を作成しようとしていることがわかります。
このリンクにアクセスした場合 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Porting_from_Google_Chrome
Chrome 拡張機能から Firefox アドオンへの移植方法に関するガイドがあります。
私の問題は、マニフェストに「アドオンID」が必要なことです
それには1つの例があり、マニフェストをこのように作成しました。
{
"background": {
"scripts": [
"background.js"
]
},
"applications": {
"gecko": {
"id": "kwstasna13@gmail.com",
"strict_min_version": "3.1.3",
"strict_max_version": "50.*"
}
},
"browser_action": {
"default_icon": "img/icon19.png",
"default_title": "iFB PRO v3 The Ultimate Tool for Invites in Facebook",
"default_popup": "popup.html"
},
"icons": {
"19": "img/icon19.png",
"38": "img/icon38.png",
"48": "img/icon_48_2.png",
"128": "img/icon_128.png"
},
"manifest_version": 2,
"name": "iFB PRO for Facebook Invites Events&Pages",
"description": " This is the ULTIMATE Invite Tool for Events and Pages in Facebook!! ",
"permissions": [ "activeTab" ],
"version": "3.1.3"
}
POPUP.HTML
<html lang="en">
<head>
<script src="popup.js"></script>
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<style type="text/css" media="screen">
body { min-width:250px; min-height:700px; text-align: center; }
#click-me-l { font-size: 20px; }
#click-me-f { font-size: 20px; }
.btnExample
{
color: #FFFFFF;
background: #5CADFF;
font-weight: bold;
border: 5px solid #ff;
}
.btnExample:hover
{
color: #FFFFFF;
background: #2E8AE6;
cursor: pointer;
}
.btnExample1
{
color: #FFFFFF;
background: #5CADFF;
font-weight: bold;
border: 5px solid #ff;
}
.btnExample1:hover
{
color: #FFFFFF;
background: #2E8AE6;
cursor: pointer;
}
</style>
</head>
<body>
<body bgcolor="#3B5998">
<img src="img/ifb-sketo.png">
<font color="white"><h1>Click here to invite friends to Pages</h1></font>
<button id='click-me-l' class="btnExample">Pages</button>
<font color="white"><h1>Click here to invite friends to Events</h1></font>
<button id='click-me-f' class="btnExample1">Events</button>
<br><font color="white"><h2>Please consider a donation in my PayPal account. Click the image below!</h2></font>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHHgYJKoZIhvcNAQcEoIIHDzCCBwsCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYA+syisLQSQYKKYV2flro8FeJ7jpnzmj3f60YrrniTdi8lGWQFJn8tG3T1CUe6BPGqv33BN5O9EMyu9YKfFZt/YG2+bsFxK/Br3+4QdjKPYj8h8yQGpaLgLBUFJLL+p5SwGU93F4pNduwtwFAmxE9ZNM8VzzQFsHjhNgmvhF1eTZzELMAkGBSsOAwIaBQAwgZsGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIZthDBP9Nfg+AeEdoN7bGj7ImUs/w9jfYsub5Olumsf3JHOT7SGgcuiWhmmNjA7Gv/A4UcIQNJXqYUAmcTl47QWaxEnMEqYSdaoHP8r5K8VEjhRxuEvMjdwN1vEeh/wfWabXC04XuG8Rq18MK2qafI8grjZ2xj13JsnNaha77qYwUy6CCA4cwggODMIIC7KADAgECAgEAMA0GCSqGSIb3DQEBBQUAMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbTAeFw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lQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE1MDMyOTE5NDkwNVowIwYJKoZIhvcNAQkEMRYEFP1O9uxzCECFuxivqbnASlt7CRGbMA0GCSqGSIb3DQEBAQUABIGAcVjNbmfaC6nAWPeC8U8sJH61V5CvL8tmh2VpqmZd9CJZwKgsbcNEIQ3WkrS/0K8Ml+QhMOqaMNw4bdzfbzepF3AqS7sGTwDyIfUVsvKmP6zm0oeWSh4MmvP3KCuWvxJUl2HwOfgXq6YOPP0JGBHE1g36NOv3vytTkhFN2hM49UE=-----END PKCS7-----
">
<input type="image" target="_blank" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img target="_blank" alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<font color="white"><h2>Click the image below to Like Us on Facebook</h2></font>
<a href="https://www.facebook.com/pages/IFB-Invite-all-to-Events-and-Pages/284580485083298" target="_blank"><img src="img/like.png">
</body>
</html>
POPUP.JS
function clickHandler1(e) {
chrome.extension.sendMessage({directive: "popup-click-l"}, function(response) {
this.close(); // close the popup when the background finishes processing request
});
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('click-me-l').addEventListener('click', clickHandler1);
})
function clickHandler2(e) {
chrome.extension.sendMessage({directive: "popup-click-f"}, function(response) {
this.close(); // close the popup when the background finishes processing request
});
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('click-me-f').addEventListener('click', clickHandler2);
})
背景.JS
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
switch (request.directive) {
case "popup-click-l":
// execute the content script
chrome.tabs.executeScript(null, { // defaults to the current tab
file: "pages.js", // script to inject into page and run in sandbox
allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
});
sendResponse({}); // sending back empty response to sender
break;
case "popup-click-f":
// execute the content script
chrome.tabs.executeScript(null, { // defaults to the current tab
file: "events.js", // script to inject into page and run in sandbox
allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
});
sendResponse({}); // sending back empty response to sender
break;
}
}
);
chrome.runtime.onInstalled.addListener( function(details) {
switch(details.reason) {
case "install":
chrome.tabs.create({url: "https://www.facebook.com/pages/IFB-Invite-all-to-Events-and-Pages/284580485083298?sk=app_128953167177144&ref=page_internal"});
break;
case "update":
break;
}
});
そして、内部に単純な JavaScript コードを含む 2 つの js ファイルがあります。
毎晩Firefoxに拡張機能を完全にインストールすると、popup.htmlが開きますが、ボタンを押してもJavaScriptコードが実行されません。
なぜ機能しないのか、誰にもわかりませんか?
クロム拡張として、それは完璧に機能します。