Skip to content

Commit

Permalink
added hideElements
Browse files Browse the repository at this point in the history
  • Loading branch information
queeeeeeee authored Jul 18, 2024
1 parent ae4ac98 commit fc29a51
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 19 deletions.
15 changes: 10 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ const OnResult = (result) => {};

async function OnChangeLogo() {
const activeTab = await getActiveTabURL();
var message = "changeLogo"

chrome.tabs.sendMessage(activeTab.id, message, OnResult);
chrome.storage.sync.get(["hideElements"], function(items){
var message = {
type: "changeLogo",
hideElements: items["hideElements"]
}

chrome.tabs.sendMessage(activeTab.id, message, OnResult);
});
}

async function OnMakeButton() {
Expand All @@ -28,7 +33,6 @@ async function OnMakeRandomButton() {
chrome.tabs.sendMessage(activeTab.id, message, OnResult);
}


function checkIsTwitter(tab) {
return (tab.url.indexOf("twitter.com") != -1 || tab.url.indexOf("x.com") != -1)
}
Expand Down Expand Up @@ -56,4 +60,5 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
OnMakeButton();
}
}
})
})

51 changes: 46 additions & 5 deletions contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ async function findObjectAll(findQuery) {



async function changeLogo(text, backgroundColor, coordinates) {
async function changeLogo(message) {
if(!message.hideElements)
return

element = await findObject('[rel="shortcut icon"]');
if (element) {
var originalElement = element;
var clonedElement = originalElement.cloneNode(true);
clonedElement.href = "//abs.twimg.com/favicons/twitter.2.ico"
clonedElement.id = "new icon";
var parentElement = originalElement.parentNode;
parentElement.insertBefore(clonedElement, originalElement.nextSibling);
parentElement.removeChild(originalElement);
}

var element = await findObject('[href="/home"]');
if (element.childNodes.length > 0) {
const pathElement = element.childNodes[0].childNodes[0].childNodes[0].childNodes[0];
Expand All @@ -56,6 +70,32 @@ async function changeLogo(text, backgroundColor, coordinates) {
pathElement.setAttribute('d', logo);
}
}

element = await findObject('[aria-label="그록"]');
if (element) {
element.style.cssText = 'display: None;'
}

element = await findObject('[aria-label="Premium"]');
if (element) {
element.style.cssText = 'display: None;'
}

element = await findObject('[aria-label="커뮤니티"]');
if (element) {
element.style.cssText = 'display: None;'
}

element = await findObject('[aria-label="Premium 구독하기"]');
if (element) {
element.style.cssText = 'display: None;'
}

element = await findObject('[aria-label="인증된 조직"]');
if (element) {
element.style.cssText = 'display: None;'
}

}

async function makeButton() {
Expand Down Expand Up @@ -497,6 +537,7 @@ async function OnTweetClean(message) {

async function OnHeartClean(message) {


var skipSet = new Set();
var totalDeleteCount = 0

Expand Down Expand Up @@ -529,7 +570,7 @@ async function OnHeartClean(message) {
var beforeScroll = window.scrollY
window.focus();
window.scrollBy(0, 500);
await sleep(300);
await sleep(message.delay);
var nowScroll = window.scrollY

if (beforeScroll != nowScroll) {
Expand All @@ -548,14 +589,14 @@ async function OnHeartClean(message) {


chrome.runtime.onMessage.addListener((obj, sender, response) => {
if (obj === "changeLogo")
changeLogo();
else if (obj === "makeButton")
if (obj === "makeButton")
makeButton();
else if (obj === "makeRandomButton")
makeRandomButton();
else if (obj.isDeleteHeart)
OnHeartClean(obj);
else if (obj.deleteMytweet || obj.deleteRetweet)
OnTweetClean(obj);
else if (obj.type === "changeLogo")
changeLogo(obj);
});
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Twitter Utility.",
"version": "1.1",
"version": "1.5",
"description": "Twitter Utility.",
"manifest_version": 3,
"background": {
Expand All @@ -15,5 +15,5 @@
"default_title": "Twitter Utility",
"default_popup": "popup.html"
},
"permissions": ["tabs"]
"permissions": ["tabs","storage"]
}
6 changes: 5 additions & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@
}
</style>

<body style="margin-bottom: 5rem;">
<body style="margin-bottom: 6rem;">
<h1 style="text-align: center;">Twitter Utility</h1>
<div style="display: flex; align-items: center; justify-content: center; margin: 1rem;">
<input type="checkbox" id="hideElements">
<label for="hideElements">이상한 것들 숨기기</label>
</div>
<div class="slidecontainer" style="text-align: center;">
<input type="range" min="30" max="500" value="100" id="DelayRange">
<h4>딜레이 : <span id="delayValue"></span>ms</h4>
Expand Down
34 changes: 28 additions & 6 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@ const OnResult = (result) => {};

async function OnChangeLogo() {
const activeTab = await getActiveTabURL();
var message = {
type: "changeLogo"
}

chrome.tabs.sendMessage(activeTab.id, message, OnResult);
chrome.storage.sync.get(["hideElements"], function(items){
var message = {
type: "changeLogo",
hideElements: items["hideElements"]
}

chrome.tabs.sendMessage(activeTab.id, message, OnResult);
});
}

function refreshCurrentTab() {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var tab = tabs[0];
chrome.tabs.reload(tab.id,{ bypassCache: true });
});
}


const OnHeartClean = async() => {
const activeTab = await getActiveTabURL();
var slider = document.getElementById("DelayRange");
var message = {
delay: -1,
delay: slider.value,
deleteRetweet: false,
deleteMytweet: false,
isDeleteHeart: true
Expand Down Expand Up @@ -70,6 +81,17 @@ document.addEventListener("DOMContentLoaded", async() => {
output.innerHTML = this.value;
}

var hideElement = document.getElementById("hideElements");
hideElement.addEventListener('change', function() {
chrome.storage.sync.set({ "hideElements": this.checked }, function(){
refreshCurrentTab()
});
});

chrome.storage.sync.get(["hideElements"], function(items){
hideElement.checked = items["hideElements"];
});

if (checkIsTwitter(activeTab) && activeTab.url.includes("with_replies")) {
const container = document.getElementsByName("container")[0];
container.innerHTML = '';
Expand Down

0 comments on commit fc29a51

Please sign in to comment.