Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Valdo Ryu committed Dec 4, 2024
1 parent 03f0f17 commit ae2f744
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
72 changes: 46 additions & 26 deletions content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ let oldResponse = {}
async function doIt(response) {
if (JSON.stringify(oldResponse) == JSON.stringify(response)) return

const enabled = response['main-toggle']

// checks if filter needs updating, used below
function res(field, bool) {
const changed =
Expand Down Expand Up @@ -40,24 +38,34 @@ async function doIt(response) {
}

// Hide feed
const enabled = response['main-toggle']

let feedKeywords = getFeedKeywords(response)
let jobKeywords = getJobKeywords(response)

if (enabled && res('hide-whole-feed', true)) {
toggleFeed(true)
hideOther('feeds')
clearInterval(feedKeywordInterval)
resetBlockedPosts()
resetAllPosts()
} else if (
(enabled && res('hide-whole-feed', false)) ||
feedKeywords != oldFeedKeywords
) {
toggleFeed(false)
showOther('feeds')
clearInterval(feedKeywordInterval)
resetBlockedPosts()
resetAllPosts()
blockByFeedKeywords(feedKeywords, response['disable-postcount-prompt'])
}

// Hide jobs
if (enabled && jobKeywords != oldJobKeywords) {
clearInterval(jobKeywordInterval)
resetAllPosts()
blockByJobKeywords()
}

if (res('main-toggle', false)) {
//Feed
toggleFeed(false)
Expand Down Expand Up @@ -151,12 +159,14 @@ async function doIt(response) {
hideOther('premium-upsell-link', false)
hideOther('gp-promo-embedded-card-three__card')
hideOther('artdeco-card overflow-hidden ph1 mb2', false)
hideOther('artdeco-card premium-accent-bar', false)
hideOtherByIndex('artdeco-tab ember-view', 1, false)
} else if (res('main-toggle', false) || res('hide-premium', false)) {
showOther('premium-upsell-link')
showOther('gp-promo-embedded-card-three__card')
showOther('artdeco-card overflow-hidden ph1 mb2', false)
showOtherByIndex('artdeco-tab ember-view', 1, false)
showOther('artdeco-card overflow-hidden ph1 mb2')
showOther('artdeco-card premium-accent-bar')
showOtherByIndex('artdeco-tab ember-view', 1)
}

// Hide news
Expand All @@ -174,26 +184,21 @@ async function doIt(response) {
showOther('notification-badge__count')
}

if (res('hide-job-guidance', true)) {
// Jobs

if (enabled && res('hide-job-guidance', true)) {
hideOther('artdeco-card mb2 pt5 pb4', false)
} else if (res('main-toggle', false) || res('hide-job-guidance', false)) {
showOther('artdeco-card mb2 pt5 pb4')
}

// Hide AI button
if (res('hide-ai-button', true)) {
if (enabled && res('hide-ai-button', true)) {
hideOther('ember-view link-without-hover-state artdeco-button', false)
} else if (res('main-toggle', false) || res('hide-ai-button', false)) {
showOther('ember-view link-without-hover-state artdeco-button')
}

// Hide jobs by keywords
let jobKeywords = response['job-keywords'].split(',')

if (jobKeywords.length > 0) {
blockByJobKeywords(jobKeywords)
}

oldResponse = response
}

Expand Down Expand Up @@ -240,6 +245,9 @@ async function toggleFeed(shown) {
async function hideOther(className, showIcon = true, forcedMode = null) {
const elements = await waitForClassName(className)

if (className === 'discovery-templates-jobs-feed-discovery-module') {
return
}
for (let el of elements) {
el.classList.remove('hide', 'dim', 'showIcon')
el.classList.add(forcedMode || mode)
Expand Down Expand Up @@ -280,8 +288,8 @@ let oldFeedKeywords = []
let oldJobKeywords = []
let runs = 0

function resetBlockedPosts() {
console.log(`LinkOff: Reset blocked posts (${runs} runs)`)
function resetAllPosts() {
console.log(`LinkOff: Reset all posts (${runs} runs)`)
let posts = document.querySelectorAll(
'[data-id*="urn:li:activity"][data-hidden=false], [data-id*="urn:li:aggregate"][data-hidden=false], [data-occludable-job-id][data-hidden=false]'
)
Expand All @@ -292,8 +300,8 @@ function resetBlockedPosts() {
})
}

function resetAllPosts() {
console.log(`LinkOff: Resetting all posts`)
function resetBlockedPosts() {
console.log(`LinkOff: Resetting blocked posts`)
let posts = document.querySelectorAll(
'[data-id*="urn:li:activity"][data-hidden=true], [data-id*="urn:li:aggregate"][data-hidden=true], [data-occludable-job-id][data-hidden=true]'
)
Expand Down Expand Up @@ -340,13 +348,13 @@ function getFeedKeywords(res) {
if (res['hide-suggested']) feedKeywords.push('Suggested')
if (res['hide-carousels']) feedKeywords.push('iframe')

console.log('LinkOff: Current keywords are', feedKeywords)
console.log('LinkOff: Current feed keywords are', feedKeywords)
return feedKeywords
}

function blockByFeedKeywords(keywords, disablePostCount) {
if (oldFeedKeywords.some((kw) => !keywords.includes(kw))) {
resetAllPosts()
resetBlockedPosts()
}

oldFeedKeywords = keywords
Expand All @@ -355,7 +363,7 @@ function blockByFeedKeywords(keywords, disablePostCount) {

if (keywords.length)
feedKeywordInterval = setInterval(() => {
if (runs % 10 == 0) resetBlockedPosts()
if (runs % 10 == 0) resetAllPosts()
// Select posts which are not already hidden
posts = document.querySelectorAll(
'[data-id*="urn:li:activity"]:not([data-hidden]), [data-id*="urn:li:aggregate"]:not([data-hidden])'
Expand Down Expand Up @@ -404,25 +412,37 @@ function blockByFeedKeywords(keywords, disablePostCount) {
}, 350)
}

function getJobKeywords(res) {
let jobKeywords =
res['job-keywords'] == '' ? [] : res['job-keywords'].split(',')

if (res['hide-promoted-jobs']) {
jobKeywords.push('Promoted')
}

console.log('LinkOff: Current job keywords are', jobKeywords)
return jobKeywords
}

function blockByJobKeywords(keywords) {
if (!window.location.href.startsWith('https://www.linkedin.com/jobs/')) {
return
}

if (oldJobKeywords.some((kw) => !keywords.includes(kw))) {
resetAllPosts()
resetBlockedPosts()
}

oldFeedKeywords = keywords
oldJobKeywords = keywords

let posts

if (keywords.length)
jobKeywordInterval = setInterval(() => {
if (runs % 10 == 0) resetBlockedPosts()
if (runs % 10 == 0) resetAllPosts()
// Select posts which are not already hidden
posts = document.querySelectorAll(
'[data-occludable-job-id]:not([data-hidden])'
'[data-occludable-job-id]:not([data-hidden]),.discovery-templates-vertical-list__list-item'
)

console.log(`LinkOff: Found ${posts.length} unblocked jobs`)
Expand Down
5 changes: 5 additions & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ <h2 class="title is-2 has-text-centered">Link Off</h2>
<label for="hide-ai-button">Hide AI button</label>
</div>

<div class="field">
<input id="hide-promoted-jobs" class="switch" type="checkbox" />
<label for="hide-promoted-jobs">Hide promoted</label>
</div>

<div class="divider">Hide jobs by keywords</div>

<div class="field">
Expand Down
1 change: 1 addition & 0 deletions service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ chrome.runtime.onInstalled.addListener((details) => {
'hide-carousels': false,
'hide-job-guidance': false,
'hide-ai-button': false,
'hide-promoted-jobs': false,
})
})
}
Expand Down

0 comments on commit ae2f744

Please sign in to comment.