Skip to content

Commit

Permalink
0.7.2
Browse files Browse the repository at this point in the history
+ UI
+ ON / OFF -väriscripti, rybohide
+ parannuksia
etc
  • Loading branch information
uncrypt3d committed Aug 22, 2024
1 parent aad78b3 commit 56eb60d
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 125 deletions.
Binary file added background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// background.js
// kesken.
//background.js

chrome.runtime.onInstalled.addListener(() => {
console.log('installed.');
});

241 changes: 139 additions & 102 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,67 @@
//'asetukset'
let highlightEnabled = true;
let hidePostsEnabled = true;
let postIds = [];

function removeCSSRules() {
const stylesheets = document.styleSheets;

for (let i = 0; i < stylesheets.length; i++) {
const stylesheet = stylesheets[i];
Array.from(stylesheets).forEach(stylesheet => {
try {
const rules = stylesheet.cssRules || stylesheet.rules;
if (!rules) continue;
if (!rules) return;

for (let j = rules.length - 1; j >= 0; j--) {
const rule = rules[j].cssText;

if (rule.includes("#navbar .button-gold-buy") ||
rule.includes("a.button-gold-buy") ||
rule.includes("a.button-gold-buy @media (max-width: 900px)")) {

stylesheet.deleteRule(j);
}
}
} catch (e) {
console.error("Can't touch css: ", e);
console.error("Unable to modify stylesheet:", e);
}
}
});
}

removeCSSRules();

const targetButtons = document.querySelectorAll('.button.button-gold-buy');

targetButtons.forEach(buttonElement => {
buttonElement.removeAttribute('onclick');
function replaceGoldBuyButtons() {
const targetButtons = document.querySelectorAll('.button.button-gold-buy');

if (buttonElement.tagName.toLowerCase() === 'a') {
buttonElement.removeAttribute('href');
}
targetButtons.forEach(buttonElement => {
buttonElement.removeAttribute('onclick');
if (buttonElement.tagName.toLowerCase() === 'a') {
buttonElement.removeAttribute('href');
}

const newButtonElement = buttonElement.cloneNode(true);
buttonElement.parentNode.replaceChild(newButtonElement, buttonElement);
const newButtonElement = buttonElement.cloneNode(true);
buttonElement.parentNode.replaceChild(newButtonElement, buttonElement);

newButtonElement.innerHTML = '';
newButtonElement.innerHTML = '';

const scrollToTopButton = createScrollButton('^', scrollToTop);
const scrollToBottomButton = createScrollButton('v', scrollToBottom);
newButtonElement.appendChild(createScrollButton('^', scrollToTop));
newButtonElement.appendChild(createScrollButton('v', scrollToBottom));
});
}

newButtonElement.appendChild(scrollToTopButton);
newButtonElement.appendChild(scrollToBottomButton);
});
replaceGoldBuyButtons();

function createScrollButton(symbol, scrollFunction) {
const button = document.createElement('button');
button.innerText = symbol;
button.style.padding = '10px';
button.style.margin = '5px';
button.style.fontSize = '18px';
button.style.backgroundColor = '#333';
button.style.color = '#fff';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.style.cssText = `
padding: 10px;
margin: 5px;
font-size: 18px;
background-color: #333;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
`;
button.addEventListener('click', scrollFunction);
return button;
}
Expand All @@ -69,93 +74,125 @@ function scrollToBottom() {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}

//väriscripti
function applyPostHighlighting() {
const baseURL = 'https://ylilauta.org/sodat/';

if (window.location.href.startsWith(baseURL)) {
function highlightPosts() {
const config = { upvoteThreshold: 5 };

function processPost(post) {
const upvoteElement = post.querySelector(".post-button .post-upvotes");
if (upvoteElement) {
const upvoteCount = parseInt(upvoteElement.textContent);
if (upvoteCount > config.upvoteThreshold) {
post.style.border = "3px solid green";
post.style.backgroundColor = "rgba(0, 255, 0, 0.1)";
}
const config = { upvoteThreshold: 5 };

function processPost(post) {
const upvoteElement = post.querySelector(".post-button .post-upvotes");
if (upvoteElement) {
const upvoteCount = parseInt(upvoteElement.textContent);
if (upvoteCount > config.upvoteThreshold) {
post.style.border = "3px solid green";
post.style.backgroundColor = "rgba(0, 255, 0, 0.1)";
}
}

document.querySelectorAll(".post").forEach(processPost);
}

highlightPosts();
document.querySelectorAll(".post").forEach(processPost);
}
console.log('Highlighting enabled');
}

applyPostHighlighting();


//hidelista
function hideUsers(ids) {
ids.forEach(id => {
const elements = document.querySelectorAll(`[data-action="Thread.hideUser"][data-user-id="${id}"]`);

if (elements.length === 0) {
console.log(`No elements found to hide for ID ${id}`);
}

elements.forEach(element => {
console.log(`Attempting to hide user with ID ${id}`);
if (element.tagName.toLowerCase() === 'button') {
element.click();
} else {
console.log(`Element with ID ${id} is not a button`);
}
});
function removePostHighlighting() {
document.querySelectorAll(".post").forEach(post => {
post.style.border = '';
post.style.backgroundColor = '';
});
}

console.log('Highlighting disabled');
}

function hidePosts(ids) {
document.querySelectorAll('.post').forEach(post => {

const userId = post.getAttribute('data-user-id');

if (userId && ids.includes(userId)) {
console.log(`Hiding post with user ID ${userId}`);
post.style.display = 'none';
}
const userId = post.getAttribute('data-user-id');
if (userId && ids.includes(userId)) {
post.style.display = 'none';
}
});
}
console.log('Posts hidden');
}

if (window.location.pathname.includes('/sodat/')) {
function showPosts(ids) {
document.querySelectorAll('.post').forEach(post => {
const userId = post.getAttribute('data-user-id');
if (userId && ids.includes(userId)) {
post.style.display = '';
}
});
console.log('Posts shown');
}
chrome.storage.local.get(['highlightEnabled', 'hidePostsEnabled', 'postIds'], function(data) {
highlightEnabled = data.highlightEnabled !== undefined ? data.highlightEnabled : true;
hidePostsEnabled = data.hidePostsEnabled !== undefined ? data.hidePostsEnabled : true;
postIds = data.postIds || [];

if (highlightEnabled) {
applyPostHighlighting();
}
if (hidePostsEnabled) {
hidePosts(postIds);
}
});

// #HIDELISTA
if (window.location.pathname.includes('/sodat/')) {
(function() {
const regex = /^#HIDELISTA/;

const postMessages = document.querySelectorAll('.post-message');

let ids = [];
postMessages.forEach(message => {
if (regex.test(message.textContent)) {
const messageText = message.textContent;

ids = Array.from(messageText.matchAll(/ID\s?([0-9]+)\s?/g)).map(r => r[1]);
console.log('IDs extracted:', ids);

return;
const regex = /^#HIDELISTA/;

const postMessages = document.querySelectorAll('.post-message');

let ids = [];
postMessages.forEach(message => {
if (regex.test(message.textContent)) {
const messageText = message.textContent;

ids = Array.from(messageText.matchAll(/ID\s?([0-9]+)\s?/g)).map(r => r[1]);
console.log('IDs extracted:', ids);

// Update post IDs
chrome.storage.local.set({ postIds: ids });

return;
}
});

if (ids.length > 0) {
hidePosts(ids);
} else {
console.log('No matching message with IDs found');
}
});

if (ids.length > 0) {
hidePosts(ids);
} else {
console.log('No matching message with IDs found');
}
})();
}



}

function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}

chrome.runtime.onMessage.addListener(debounce((request, sender, sendResponse) => {
if (request.type === 'TOGGLE_HIGHLIGHT') {
highlightEnabled = request.enable;
if (highlightEnabled) {
applyPostHighlighting();
} else {
removePostHighlighting();
}
chrome.storage.local.set({ highlightEnabled });
}

if (request.type === 'TOGGLE_HIDE_POSTS') {
hidePostsEnabled = request.enable;
postIds = request.ids || [];
if (hidePostsEnabled) {
hidePosts(postIds);
} else {
showPosts(postIds);
}
chrome.storage.local.set({ hidePostsEnabled, postIds });
}
}, 300));
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"manifest_version": 3,
"name": "KELA-GOLD",
"version": "0.7.1",
"version": "0.7.2",
"description": "Golden Ylis addon.",
"permissions": ["activeTab", "scripting", "downloads"],
"permissions": ["activeTab", "scripting", "storage"],
"action": {
"default_popup": "popup.html"
},
Expand Down
Loading

0 comments on commit 56eb60d

Please sign in to comment.