Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
292 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { mvIgniteStore } from "../utils/store"; | ||
import { | ||
getSubForumContainerElement, | ||
isFeaturedThreads, | ||
isHomepage, | ||
} from "../injected/utils/loader"; | ||
import { rerenderConfigurationMenuRoot } from "../injected/configuration"; | ||
|
||
export type Thread = { | ||
url: string; | ||
forumSlug: string; | ||
title: string; | ||
thumbnail?: string; | ||
hasLive?: boolean; | ||
urlSinceLastVisit?: string | null; | ||
responsesSinceLastVisit?: number; | ||
userResponseAt?: string | null; | ||
lastActivityAt?: string; | ||
createdAt?: string; | ||
totalResponses?: string; | ||
userLastResponse?: { | ||
username: string; | ||
avatar: string; | ||
}; | ||
}; | ||
|
||
export const getThreadId = (threadUrl: string) => { | ||
const urlSplit = threadUrl.split("-"); | ||
return urlSplit[urlSplit.length - 1]; | ||
}; | ||
|
||
export const addThreadToIgnore = (threadUrl: string) => { | ||
const ignoredThreads = mvIgniteStore.get().ignoredThreads ?? []; | ||
ignoredThreads.push(threadUrl); | ||
mvIgniteStore.set("ignoredThreads", [...new Set(ignoredThreads)]); | ||
|
||
ignoreThreads(); | ||
// this is a hack, should be better implemented | ||
rerenderConfigurationMenuRoot(); | ||
console.log(`MV-Ignited: Thread ${threadUrl} ignored`); | ||
}; | ||
|
||
export const ignoreThreads = () => { | ||
const ignoredThreads = mvIgniteStore.get().ignoredThreads; | ||
const ignoredThreadsIds = ignoredThreads.map((threadUrl) => | ||
getThreadId(threadUrl), | ||
); | ||
|
||
if (ignoredThreads.length) { | ||
if (isHomepage()) { | ||
document | ||
.querySelectorAll(".mv-ignite--thread") | ||
?.forEach((threadElement) => { | ||
const idSplit = threadElement.id?.split("-"); | ||
if (ignoredThreadsIds.includes(idSplit[idSplit.length - 1])) { | ||
threadElement?.setAttribute("style", "display:none"); | ||
} else { | ||
threadElement?.setAttribute("style", ""); | ||
} | ||
}); | ||
} | ||
|
||
if (isFeaturedThreads()) { | ||
document.querySelectorAll("a")?.forEach((a) => { | ||
const thread = document.getElementById(`t${a.id.slice(1)}`); | ||
if (ignoredThreadsIds.includes(a.id.slice(1))) { | ||
thread?.setAttribute("style", "display:none"); | ||
} else { | ||
thread?.setAttribute("style", ""); | ||
} | ||
}); | ||
} | ||
|
||
const temasElement = getSubForumContainerElement(); | ||
if (temasElement) { | ||
for (const a of document.querySelectorAll("a")) { | ||
const thread = document.getElementById(`a${a.id.slice(1)}`); | ||
const trElement = thread?.parentElement?.parentElement?.parentElement; | ||
|
||
if (ignoredThreadsIds.includes(a.id.slice(1))) { | ||
trElement?.setAttribute("style", "display:none"); | ||
} else { | ||
trElement?.setAttribute("style", ""); | ||
} | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const injectThreads = () => { | ||
// Nothing yet | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const showBody = () => { | ||
const body = document.getElementsByTagName("body").item(0); | ||
body?.setAttribute("style", "opacity: 1 !important;"); | ||
}; | ||
export const hideBody = () => { | ||
const body = document.getElementsByTagName("body").item(0); | ||
body?.setAttribute("style", "opacity: 0 !important;"); | ||
}; | ||
|
||
export const showContent = () => { | ||
const content = document.getElementById("content"); | ||
content?.setAttribute("style", "opacity: 1 !important;"); | ||
}; | ||
export const hideContent = () => { | ||
const content = document.getElementById("content"); | ||
content?.setAttribute("style", "opacity: 0 !important;"); | ||
}; | ||
|
||
export const isHomepage = () => !!document.getElementById("index"); | ||
export const isThread = () => !!document.getElementById("post-container"); | ||
export const getSubForumContainerElement = () => | ||
document.getElementById("temas"); | ||
export const isSubForumThreads = () => !!getSubForumContainerElement(); | ||
export const isFeaturedThreads = () => | ||
document.getElementById("top") || | ||
document.getElementById("foros_spy") || | ||
document.getElementById("featured") || | ||
document.getElementById("unread") || | ||
document.getElementById("new"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.