Explorar o código

Init - based on https://gist.github.com/danharper/8364399

Owen Diffey %!s(int64=3) %!d(string=hai) anos
achega
dcb798982f
Modificáronse 6 ficheiros con 96 adicións e 0 borrados
  1. 6 0
      chrome/background.js
  2. 7 0
      chrome/inject.js
  3. 27 0
      chrome/manifest.json
  4. 24 0
      firefox/background.js
  5. 5 0
      firefox/inject.js
  6. 27 0
      firefox/manifest.json

+ 6 - 0
chrome/background.js

@@ -0,0 +1,6 @@
+chrome.browserAction.onClicked.addListener(function (tab) {
+	// for the current tab, inject the "inject.js" file & execute it
+	// chrome.tabs.executeScript(tab.ib, {
+	// 	file: 'inject.js'
+	// });
+});

+ 7 - 0
chrome/inject.js

@@ -0,0 +1,7 @@
+(function() {
+    document.addEventListener("DOMContentLoaded", function () {
+        document.getElementById("nav").addEventListener("click", function () {
+            console.log(111);
+        });
+    });
+})();

+ 27 - 0
chrome/manifest.json

@@ -0,0 +1,27 @@
+{
+  "name": "JSInject",
+  "description": "JSInject",
+  "version": "0.0.1",
+  "manifest_version": 2,
+  "permissions": [
+      "storage",
+      "activeTab"
+  ],
+  "background": {
+    "scripts": [
+      "background.js"
+    ],
+    "persistent": true
+  },
+  "browser_action": {
+    "default_title": "Inject!"
+  },
+  "content_scripts": [{
+      "matches": [
+          "http://*/*",
+          "https://*/*"
+      ],
+      "js": ["inject.js"],
+      "run_at": "document_start"
+  }]
+}

+ 24 - 0
firefox/background.js

@@ -0,0 +1,24 @@
+'use strict';
+
+let registered = null;
+
+async function registerScript(message) {
+  const {
+    hosts,
+    code,
+    userScriptID,
+  } = message;
+
+  if (registered) {
+    await registered.unregister();
+    registered = null;
+  }
+
+  registered = await browser.userScripts.register({
+    matches: hosts,
+    js: [{code}],
+    scriptMetadata: {userScriptID},
+  });
+}
+
+browser.runtime.onMessage.addListener(registerScript);

+ 5 - 0
firefox/inject.js

@@ -0,0 +1,5 @@
+document.addEventListener("DOMContentLoaded", function () {
+	document.getElementById("nav").addEventListener("click", function () {
+		console.log(111);
+	});
+});

+ 27 - 0
firefox/manifest.json

@@ -0,0 +1,27 @@
+{
+  "name": "JSInject",
+  "description": "JSInject",
+  "version": "0.0.1",
+  "manifest_version": 2,
+  "permissions": [
+      "storage",
+      "activeTab"
+  ],
+  "background": {
+    "scripts": [
+      "background.js"
+    ],
+    "persistent": true
+  },
+  "browser_action": {
+    "default_title": "Inject!"
+  },
+  "content_scripts": [{
+      "matches": [
+          "http://*/*",
+          "https://*/*"
+      ],
+      "js": ["inject.js"],
+      "run_at": "document_start"
+  }]
+}