Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="dist/bg.js"></script>
</head>
<body>
</body>
</html>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</head>
<body>
<div id="app"></div>
<script src="/dist/build.js"></script>
<script src="/dist/main.js"></script>
</body>
</html>
16 changes: 11 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
"48": "icons/splitscreen-48.png",
"128": "icons/splitscreen-128.png"
},
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": {
"16": "icons/splitscreen-16.png"
},
"default_title": "Click to open Split Screen"
},
"permissions": [
"management",
"storage",
"webRequest",
"webRequestBlocking",
"<all_urls>"
],
"chrome_url_overrides": {
"newtab": "index.html"
}
}
]
}
45 changes: 45 additions & 0 deletions src/bg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
(function () {
const _LOG_ = localStorage.log;
const UA = navigator.userAgent;
const WebExtensions = UA.includes("Chrome") ? chrome : browser;
const manifest = WebExtensions.runtime.getManifest();
if (_LOG_) {
console.log(...logGen(null, manifest.name, manifest.version + " start"));
};
WebExtensions.browserAction.onClicked.addListener((tab) => {
if (_LOG_) {
console.log(...logGen(tab.id, "browserAction.onClicked", ""));
}
WebExtensions.tabs.create({ url:"/index.html", active: true }, (newTab) => {
if (!handleError("tabs.create")()) {
console.log(...logGen(tab.id, "tabs.create", " ok"));
} else {
console.log(...logGen(tab.id, "tabs.create", " failed"));
}
});
});
function handleError(label) {
return () => {
if (WebExtensions.runtime.lastError) {
if (_LOG_) {
console.error(...logGen(label, "chrome.runtime.lastError", WebExtensions.runtime.lastError.message));
}
return true;
}
return false;
};
};
function logColor(tabId) {
const _r = tabId % 64;
return "color:#" + ((_r >> 4 & 3) << 22 | (_r >> 2 & 3) << 14 | (_r & 3) << 6 | 1048576).toString(16);
}
function logGen(tabId, eventName, message) {
if (tabId) {
return ["tabId %c" + tabId + "%c [" + eventName + "]%c " + message, logColor(tabId), "color:#f60b91", ""];
} else {
return ["%c%c[" + eventName + "]%c " + message, logColor(tabId), "color:#f60b91", ""];
}
}
})();

9 changes: 6 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ var path = require('path')
var webpack = require('webpack')

module.exports = {
entry: './src/main.js',
entry: {
bg: './src/bg.js',
main: './src/main.js'
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
filename: '[name].js',
},
module: {
rules: [
Expand All @@ -16,7 +19,7 @@ module.exports = {
'vue-style-loader',
'css-loader'
],
}, {
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
Expand Down