|
// ==UserScript== |
|
// @name FB I Saw This! |
|
// @namespace http://tampermonkey.net/ |
|
// @version 0.1 |
|
// @description Permanently hide story from FB news feed when its scrolled out. |
|
// @author a_[w] |
|
// @match https://www.facebook.com/ |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
var iid, timeout = 1000, |
|
spaceToСhangeMind = 500, |
|
find = () => { |
|
let content = document.getElementById('contentArea'); |
|
let stories = Array.prototype.filter.call(content.querySelectorAll('div.userContentWrapper'), (story) => { |
|
let rect = story.getBoundingClientRect(); |
|
if (story.dataset.ISawThis) { |
|
return rect.bottom + spaceToСhangeMind < 0; |
|
} else if (rect.top > -100 && rect.top < window.innerHeight) story.dataset.ISawThis = true; |
|
return false; |
|
}); |
|
return stories; |
|
}, |
|
query = () => { |
|
let list = find(), |
|
next = () => { |
|
if (list.length) { |
|
//console.log('next: ', list.length - 1); |
|
click(); |
|
hide(list.shift(), next); |
|
} |
|
}; |
|
//console.log('list of', list.length); |
|
next(); |
|
}, |
|
scrollMagicNum = 60, |
|
click = () => { |
|
window.document.body.click && window.document.body.click(); |
|
}, |
|
//bodyHeight = () => document.body.getBoundingClientRect().height, |
|
scroll = (story, hideStory) => { |
|
let height = story.getBoundingClientRect().height; |
|
hideStory && hideStory(); |
|
window.scrollBy(0, -height); |
|
story.parentNode && story.parentNode.removeChild(story); |
|
}, |
|
hide = (story, next) => { |
|
let context; |
|
let parent = story.parentNode; |
|
if (story.querySelector('div.userContentWrapper a.UFILikeLink[aria-pressed="true"]')) { |
|
scroll(parent); |
|
} else context = story.querySelector('div.uiPopover a'); |
|
if (context) { |
|
context.click(); |
|
var time = Date.now(), iid = setInterval(() => { |
|
let result = false; |
|
document.querySelectorAll('div.uiLayer:not(.hidden_elem) .uiContextualLayer').forEach((layer) => { |
|
let hideLink = layer.querySelector('li.__MenuItem a[ajaxify^="/ajax/feed/filter_action/dialog_direct_action"]'); |
|
if (hideLink) { |
|
/* 1 * / |
|
let height = bodyHeight(); |
|
hideLink.click(); |
|
window.scrollBy(0, bodyHeight() - height + scrollMagicNum); |
|
/* 2 * / |
|
story.parentNode.style.minHeight = story.getBoundingClientRect().height + 'px'; |
|
hideLink.click(); |
|
/* 3 */ |
|
scroll(parent, () => hideLink.click()); |
|
//*/ |
|
result = true; |
|
} |
|
}); |
|
//console.log('interval'); |
|
if (result || Date.now() - time > 320) { |
|
//console.log(result ? ' - story hidden' : ' - context link was not found'); |
|
scroll(parent); |
|
clearInterval(iid); |
|
next(); |
|
} |
|
}, 50); |
|
} else { |
|
next(); |
|
} |
|
}, |
|
stop = () => { |
|
if (iid) { |
|
clearTimeout(iid); |
|
} |
|
iid = 0; |
|
}, |
|
start = () => { |
|
stop(); |
|
iid = setTimeout(query, timeout); |
|
}; |
|
window.addEventListener('scroll', () => { |
|
//console.log(' - scroll'); |
|
start(); |
|
}); |
|
document.addEventListener('load', (event) => { |
|
setTimeout(hide, 1000); |
|
}); |
|
})(); |