Created
October 10, 2019 07:50
-
-
Save hexagit/e979b67cb21d775c208810f2a4a1339b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // リクエストを受け取る | |
| chrome.runtime.onMessage.addListener( | |
| function (values, sender, callback) { | |
| switch (values.type) { | |
| case "OpenPage": { | |
| OpenPage(values, true); | |
| callback(values.type); | |
| break; | |
| } | |
| case "FindNotification": { | |
| Notification(values, "あった~"); | |
| callback(values.type); | |
| break; | |
| } | |
| case "NotFindNotification": { | |
| Notification(values, "なかった~"); | |
| callback(values.type); | |
| break; | |
| } | |
| } | |
| return true; | |
| } | |
| ); | |
| // ページを開く | |
| function OpenPage(values) { | |
| chrome.windows.getCurrent(function (window) { | |
| chrome.tabs.create({ | |
| 'windowId': window.windowId, | |
| 'url': "https://hexadrive.jp/hexablog/", | |
| }, function (tab) { | |
| SetJavaScript({ | |
| date: values.date, | |
| tabId: tab.id, | |
| }); | |
| }); | |
| }); | |
| } | |
| // htmlにJavascriptを設定 | |
| function SetJavaScript(values) { | |
| chrome.tabs.executeScript(values.tabId, { | |
| file: "jquery-3.4.1.min.js" | |
| }, function () { | |
| chrome.tabs.executeScript(values.tabId, { | |
| code: "var values = " + JSON.stringify(values) + ";" | |
| }, function () { | |
| chrome.tabs.executeScript(values.tabId, { | |
| file: "search.js" | |
| }); | |
| }); | |
| }); | |
| } | |
| // 通知 | |
| function Notification(values, msg) { | |
| var tabIdString = values.tabId.toString(); | |
| chrome.notifications.create(tabIdString, | |
| { | |
| type: 'basic', | |
| iconUrl: 'icon128.png', | |
| priority: 1, | |
| title: values.date, | |
| message: msg, | |
| }, function () { | |
| chrome.notifications.onClicked.addListener(function (notificationId) { | |
| if (notificationId == tabIdString) { | |
| chrome.tabs.update(values.tabId, { active: true }); | |
| } | |
| chrome.notifications.clear(tabIdString); | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment