Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Last active April 9, 2018 15:25
Show Gist options
  • Save nemtsov/24f7b4bac2ca222d55c8c3935002f86c to your computer and use it in GitHub Desktop.
Save nemtsov/24f7b4bac2ca222d55c8c3935002f86c to your computer and use it in GitHub Desktop.
Behance: Grey Out Seen Projects
// ==UserScript==
// @name Behance Grey Out Seen
// @version 1
// @grant none
// @match https://www.behance.net/*
// ==/UserScript==
const ACTIVITY_RE = /\/(activity)?$/;
const PROJECT_RE = /\/gallery\/([0-9]+)\/.+/;
let viewedProjectIds = JSON.parse(localStorage.getItem('viewedProjectIds')) || [];
function recordViewedProjectId(projectId) {
viewedProjectIds.push(projectId);
localStorage.setItem('viewedProjectIds', JSON.stringify(viewedProjectIds));
}
function markViewedProjects() {
const coverNodes = Array.from(document.querySelectorAll('.js-project-cover'));
coverNodes
.filter(coverNode => viewedProjectIds.includes(coverNode.dataset.id))
.forEach((coverNode) => {
coverNode.style.opacity = '0.3';
});
}
function onPathnameChange(pathname) {
const projectMatch = pathname.match(PROJECT_RE);
if (projectMatch) {
const projectId = projectMatch[1];
if (!viewedProjectIds.includes(projectId)) {
recordViewedProjectId(projectId);
}
}
else if (ACTIVITY_RE.test(pathname)) {
setTimeout(markViewedProjects, 1000);
}
else if (viewedProjectIds.length) {
markViewedProjects()
}
}
(function startPathPolling() {
let lastPathname;
setInterval(() => {
if (lastPathname !== location.pathname) {
lastPathname = location.pathname;
onPathnameChange(lastPathname);
}
}, 500);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment