-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from onozaty/12-supports-manifest-v3
#12 Support Manifest V3
- Loading branch information
Showing
13 changed files
with
306 additions
and
115 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
importScripts('actions.js'); | ||
importScripts('settings.js'); | ||
importScripts('user-scripts.js'); | ||
importScripts('handler.js'); | ||
importScripts('background.js'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,91 @@ | ||
Settings.newAsync().then((settings) => { | ||
const addCurrentPage = () => { | ||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { | ||
const tab = tabs[0]; | ||
chrome.runtime.openOptionsPage(() => { | ||
// It takes time to open the option page | ||
setTimeout(() => { | ||
chrome.runtime.sendMessage( | ||
{ | ||
target: 'options', | ||
name: 'add', | ||
data: { | ||
title: tab.title, | ||
action: ActionId.JUMP_URL, | ||
url: tab.url | ||
} | ||
}); | ||
}, 500); | ||
}); | ||
}); | ||
} | ||
|
||
const handler = new Handler(settings); | ||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.contextMenus.create({ | ||
id: 'add-shortcutkey2url', | ||
title: 'Add to ShortcutKey2URL', | ||
contexts: ['all'], | ||
type: 'normal', | ||
}); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
console.log(message); | ||
chrome.runtime.onStartup.addListener(() => { | ||
Settings.initialize(); | ||
}); | ||
|
||
switch(message.target) { | ||
case 'background-handler': | ||
const result = handler.handle(message); | ||
chrome.contextMenus.onClicked.addListener(function (info, tab) { | ||
if (info.menuItemId == 'add-shortcutkey2url') { | ||
addCurrentPage(); | ||
} | ||
}); | ||
|
||
console.log(result); | ||
sendResponse(result); | ||
return; | ||
const handleMessage = (message, sendResponse, handler, settings) => { | ||
|
||
case 'background-settings': | ||
if (message.name == 'load') { | ||
// load | ||
settings.reload().then(() => { | ||
sendResponse(settings.data()); | ||
}); | ||
} else { | ||
// save | ||
settings.update(message.settings).then(() => { | ||
sendResponse(settings.data()); | ||
}); | ||
} | ||
return true; | ||
switch (message.target) { | ||
case 'background-handler': | ||
const result = handler.handle(message, settings); | ||
|
||
case 'background-options': | ||
// Message name is 'add' only | ||
addCurrentPage(); | ||
return; | ||
console.log(result); | ||
sendResponse(result); | ||
return; | ||
|
||
/** Chrome only */ | ||
case 'background-shortcuts': | ||
// Message name is 'open' only | ||
chrome.tabs.create({url: 'chrome://extensions/shortcuts'}); | ||
return; | ||
case 'background-settings': | ||
if (message.name == 'load') { | ||
// load | ||
settings.reload().then(() => { | ||
sendResponse(settings.data()); | ||
}); | ||
} else { | ||
// save | ||
settings.update(message.settings).then(() => { | ||
sendResponse(settings.data()); | ||
}); | ||
} | ||
/*--------------*/ | ||
}); | ||
return; | ||
|
||
const addCurrentPage = function() { | ||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
const tab = tabs[0]; | ||
chrome.runtime.openOptionsPage(() => { | ||
// It takes time to open the option page | ||
setTimeout(() => { | ||
chrome.runtime.sendMessage( | ||
{ | ||
target: 'options', | ||
name: 'add', | ||
data: { | ||
title: tab.title, | ||
action: ActionId.JUMP_URL, | ||
url: tab.url | ||
} | ||
}); | ||
}, | ||
500); | ||
}); | ||
}); | ||
case 'background-options': | ||
// Message name is 'add' only | ||
addCurrentPage(); | ||
return; | ||
|
||
/** Chrome only */ | ||
case 'background-shortcuts': | ||
// Message name is 'open' only | ||
chrome.tabs.create({ url: 'chrome://extensions/shortcuts' }); | ||
return; | ||
} | ||
} | ||
|
||
chrome.contextMenus.create({ | ||
title: 'Add to ShortcutKey2URL', | ||
contexts: ['all'], | ||
type: 'normal', | ||
onclick: () => { | ||
addCurrentPage(); | ||
} | ||
}); | ||
}); | ||
let handler; | ||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
console.log(message); | ||
|
||
if (handler == null) { | ||
handler = new Handler(); | ||
} | ||
|
||
Settings.getCache().then((settings) => { | ||
handleMessage(message, sendResponse, handler, settings); | ||
}) | ||
|
||
return true; | ||
}); |
Oops, something went wrong.