Initial commit

master v0.1
Nikola Forró 4 years ago
commit 59007dd4da

4
.gitignore vendored

@ -0,0 +1,4 @@
.web-extension-id
improved-crowdcast-ux.xpi
improved-crowdcast-ux.crx
improved-crowdcast-ux.pem

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2020 Nikola Forró
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,17 @@
:root {
--default-chat-width: 300px;
--default-highlight-color: #FFEA9E;
}
.theatre .theatre-left {
width: calc(100% - var(--chat-width, var(--default-chat-width)) - 9px) !important;
}
.theatre .theatre-right {
width: var(--chat-width, var(--default-chat-width)) !important;
max-width: var(--chat-width, var(--default-chat-width)) !important;
}
.message-content.highlighted {
background-color: var(--highlight-color, var(--default-highlight-color)) !important;
}

@ -0,0 +1,135 @@
function setChatWidth(width) {
document.querySelector('body').style.setProperty("--chat-width", width + 'px');
}
function setHighlightColor(color) {
document.querySelector('body').style.setProperty("--highlight-color", color);
}
chrome.storage.onChanged.addListener((changes, areaName) => {
if ('chatWidth' in changes) {
setChatWidth(changes.chatWidth.newValue);
}
if ('highlightColor' in changes) {
setHighlightColor(changes.highlightColor.newValue);
}
});
chrome.storage.sync.get(null, (settings) => {
if ('chatWidth' in settings) {
setChatWidth(settings.chatWidth);
}
if ('highlightColor' in settings) {
setHighlightColor(settings.highlightColor);
}
});
class TabCompletion {
constructor() {
this.ownUsernameRegExp = null;
this.usernames = [];
}
setOwnUsername(username) {
this.ownUsernameRegExp = new RegExp('@?' + username.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi');
}
addUsername(username) {
if (!this.usernames.includes(username)) {
this.usernames.push(username);
}
}
complete(input, start, symbol, choices) {
let partial = input.value.substring(start + 1, input.selectionStart).trim();
if (partial === this[`suggestion_${symbol}`]) {
partial = this[`partial_${symbol}`];
} else {
this[`partial_${symbol}`] = partial;
}
const possibilities = choices.filter((choice) => choice.toLowerCase().startsWith(partial.toLowerCase()));
if (this[`completionIndex_${symbol}`] === undefined || ++this[`completionIndex_${symbol}`] >= possibilities.length) {
this[`completionIndex_${symbol}`] = 0;
}
if (possibilities.length > 0) {
this[`suggestion_${symbol}`] = possibilities[this[`completionIndex_${symbol}`]].trim();
input.value = input.value.substring(0, start + 1) + this[`suggestion_${symbol}`] +
' ' + input.value.substring(input.selectionStart);
input.selectionStart = start + this[`suggestion_${symbol}`].length + 2;
input.selectionEnd = input.selectionStart;
}
}
attempt(input) {
const at = input.value.lastIndexOf('@', input.selectionStart - 1);
let colon = input.value.lastIndexOf(':', input.selectionStart - 1);
// ignore colon at the end of emoji shortname
if (colon !== -1) {
const match = emojis.shortnameRegExp.exec(input.value);
if (match !== null) {
colon = match.index;
}
}
if (at !== -1 && at > colon) {
this.complete(input, at, '@', this.usernames);
} else if (colon !== -1 && colon > at) {
this.complete(input, colon, ':', emojis.shortnames.map((s => s + ':')));
} else {
return false;
}
return true;
}
}
const tabCompletion = new TabCompletion();
(new MutationObserver((mutationsList, observer) => {
for (let mutation of mutationsList) {
for (let node of mutation.addedNodes) {
if (node.nodeType === 1 && (username = node.querySelector('span.user-name')) !== null) {
(new MutationObserver((mutationsList, observer) => {
for (let mutation of mutationsList) {
tabCompletion.setOwnUsername(mutation.target.data.trim());
}
})).observe(username, {characterData: true, subtree: true});
}
if (node.nodeType === 1 && (chatInput = node.querySelector('textarea#input-chat')) !== null) {
chatInput.addEventListener('keydown', (event) => {
if (event.key == 'Tab' && tabCompletion.attempt(event.currentTarget)) {
event.preventDefault();
}
});
}
if (node.nodeType === 1 && (username = node.querySelector('a.name')) !== null) {
if (!username.text.trim().startsWith('{')) {
tabCompletion.addUsername(username.text.trim());
}
}
if (node.nodeType === 1 && (messageContent = node.querySelector('div.message-content-main')) !== null) {
if (tabCompletion.ownUsernameRegExp !== null) {
const updated = messageContent.innerHTML.replace(tabCompletion.ownUsernameRegExp,
'<span style="font-weight: bold">$&</span>');
if (messageContent.innerHTML !== updated) {
messageContent.innerHTML = updated;
messageContent.parentNode.classList.add('highlighted');
}
}
}
}
}
})).observe(document, {childList: true, subtree: true});

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

@ -0,0 +1,25 @@
{
"manifest_version": 2,
"name": "Improved Crowdcast UX",
"version": "0.1",
"icons": {
"16": "icons/16.png",
"32": "icons/32.png",
"48": "icons/48.png",
"64": "icons/64.png",
"128": "icons/128.png"
},
"browser_action": {
"default_title": "Improved Crowdcast UX",
"default_icon": "icons/32.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["https://*.crowdcast.io/*"],
"js": ["emojis.js", "content.js"],
"css": ["content.css"]
}
],
"permissions": ["activeTab", "storage", "https://*.crowdcast.io/*"]
}

@ -0,0 +1,18 @@
body {
min-width: 18em;
}
input[type="color"] {
padding: 2px 3px;
}
#content div {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0.5em 0 0.5em 0;
}
#content div > input {
flex-basis: 6em;
}

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div id="content">
<div>
<label for="chatWidth">Chat width (in pixels):</label>
<input type="number" id="chatWidth" name="chatWidth" min="200" max="1000" step="50">
</div>
<div>
<label for="highlightColor">Highlight color:</label>
<input type="color" id="highlightColor" name="highlightColor">
</div>
<div>
<button type="button" id="saveButton">Save &amp; apply</button>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>

@ -0,0 +1,20 @@
const defaultSettings = {
chatWidth: 300,
highlightColor: '#FFEA9E'
};
chrome.storage.sync.get(defaultSettings, (settings) => {
document.querySelector('#chatWidth').value = settings.chatWidth;
document.querySelector('#highlightColor').value = settings.highlightColor;
});
document.querySelector('#saveButton').addEventListener('click', (event) => {
settings = {
chatWidth: document.querySelector('#chatWidth').value,
highlightColor: document.querySelector('#highlightColor').value
}
chrome.storage.sync.set(settings, () => {
console.log('Settings saved');
});
}, false);
Loading…
Cancel
Save