added basic browser extension stuff
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
@@ -0,0 +1,66 @@
|
||||
const ignoredPages = {
|
||||
"settings": true,
|
||||
"payments": true,
|
||||
"inventory": true,
|
||||
"messages": true,
|
||||
"subscriptions": true,
|
||||
"friends": true,
|
||||
"directory": true,
|
||||
};
|
||||
|
||||
const appName = "com.chatterino.chatterino";
|
||||
|
||||
function matchUrl(url) {
|
||||
if (!url)
|
||||
return;
|
||||
|
||||
const match = url.match(/^https?:\/\/(www\.)?twitch.tv\/([a-zA-Z0-9]+)\/?$/);
|
||||
|
||||
if (match) {
|
||||
const channelName = match[2];
|
||||
|
||||
if (!ignoredPages[channelName]) {
|
||||
selectChannel(channelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var port = chrome.runtime.connectNative("com.chatterino.chatterino");
|
||||
|
||||
port.onMessage.addListener(function(msg) {
|
||||
console.log(msg);
|
||||
});
|
||||
port.onDisconnect.addListener(function() {
|
||||
console.log("Disconnected");
|
||||
});
|
||||
port.postMessage({ text: "Hello, my_application" });
|
||||
|
||||
function selectChannel(channelName) {
|
||||
console.log(channelName);
|
||||
|
||||
port.postMessage({channelName: channelName});
|
||||
|
||||
// chrome.runtime.sendNativeMessage(appName, { "xd": true }, (resp) => {
|
||||
// console.log(resp);
|
||||
// })
|
||||
}
|
||||
|
||||
/// add listeners
|
||||
chrome.tabs.onActivated.addListener((activeInfo) => {
|
||||
chrome.tabs.get(activeInfo.tabId, (tab) => {
|
||||
if (!tab)
|
||||
return;
|
||||
|
||||
if (!tab.url)
|
||||
return;
|
||||
|
||||
matchUrl(tab.url);
|
||||
});
|
||||
});
|
||||
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
if (!tab.highlighted)
|
||||
return;
|
||||
|
||||
matchUrl(changeInfo.url);
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Chatterino",
|
||||
"version": "1.0",
|
||||
"description": "xd",
|
||||
"permissions": [
|
||||
"tabs", "nativeMessaging"
|
||||
],
|
||||
"icons": {
|
||||
"256": "icon.png"
|
||||
},
|
||||
"manifest_version": 2,
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
],
|
||||
"persistent": false
|
||||
},
|
||||
"browser_action": {
|
||||
"default_popup": "popup.html"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
xd
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user