136 lines
4.5 KiB
JavaScript
136 lines
4.5 KiB
JavaScript
// ==UserScript==
|
|
// @name Facebook Ticker Filter
|
|
// @namespace com.facebook.tickerfilter
|
|
// @description Add a fild for filtering ticker events
|
|
// @include https://www.facebook.com/*
|
|
// @include http://www.facebook.com/*
|
|
// @include https://*/facebook.com/*
|
|
// @include http://*.facebook.com/*
|
|
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
|
|
// @version 1
|
|
// @grant none
|
|
// ==/UserScript==
|
|
//
|
|
/*jslint browser:true*/
|
|
(function () {
|
|
var downcount = 0;
|
|
var targetIDs = [
|
|
'cecile.tostivint.9', // target
|
|
'camillebriant', // target
|
|
'lise.duchatelet', // target
|
|
'BlandineSdAsterya', // target
|
|
'perrine.bouveret.9', // target relative (cecile.tostivint.9)
|
|
'peeters7', // interest
|
|
'c.grusondaniel', // interest
|
|
'gayane.adourian', // interest
|
|
'amelie.valentin.75', // relative (cecile.tostivint.9)
|
|
'jessehaug', // relative (cecile.tostivint.9)
|
|
'sanjarbek.khodjaev', // relative (cecile.tostivint.9)
|
|
'morgane\.parma', // relative (cecile.tostivint.9)
|
|
];
|
|
var targetRE = new RegExp('/(' + targetIDs.join('|') + ')');
|
|
//var targetRE = /\/(cecile\.tostivint\.9)/;
|
|
var scrollTicker;
|
|
scrollTicker = function () {
|
|
var ticker;
|
|
var evt;
|
|
var scroll;
|
|
//ticker = document.getElementById('pagelet_ticker');
|
|
ticker = document.getElementsByClassName('ticker_container').item(0).children.item(0).children.item(0);
|
|
console.log(ticker);
|
|
ticker.style.background = 'red';
|
|
console.log('begin com.facebook.scrollTicker');
|
|
downcount += 1;
|
|
downcount = downcount % 100;
|
|
scroll = 20;
|
|
if (downcount === 0) {
|
|
scroll *= -1;
|
|
}
|
|
evt = document.createEvent('UIEvents');
|
|
// creates a scroll event that bubbles, can be cancelled,
|
|
// and with its view and detail property initialized to window and 1,
|
|
// respectively
|
|
evt.initUIEvent('scroll', true, true, window, scroll);
|
|
ticker.dispatchEvent(evt);
|
|
console.log('debug1 com.facebook.scrollTicker');
|
|
|
|
/*
|
|
evt = document.createEvent('MouseEvents');
|
|
evt.initMouseEvent('DOMMouseScroll', // in DOMString typeArg,
|
|
true, // in boolean canBubbleArg,
|
|
true, // in boolean cancelableArg,
|
|
window, // in views::AbstractView viewArg,
|
|
10, // in long detailArg,
|
|
0, // in long screenXArg,
|
|
0, // in long screenYArg,
|
|
0, // in long clientXArg,
|
|
0, // in long clientYArg,
|
|
0, // in boolean ctrlKeyArg,
|
|
0, // in boolean altKeyArg,
|
|
0, // in boolean shiftKeyArg,
|
|
0, // in boolean metaKeyArg,
|
|
0, // in unsigned short buttonArg,
|
|
null
|
|
// in EventTarget relatedTargetArg
|
|
);
|
|
ticker.dispatchEvent(evt);
|
|
console.log('debug2 com.facebook.scrollTicker');
|
|
*/
|
|
/*
|
|
evt = document.createEvent('MouseEvents');
|
|
evt.initEvent('mousewheel', true, true);
|
|
evt.wheelDelta = scroll;
|
|
ticker.dispatchEvent(evt);
|
|
*/
|
|
console.log('end com.facebook.scrollTicker');
|
|
};
|
|
|
|
function cleanStory(story, protection) {
|
|
var hidden = 0;
|
|
var storyLink;
|
|
storyLink = story.children.item(0);
|
|
if (targetRE.test(storyLink.href)) {
|
|
console.log(storyLink.href);
|
|
hidden = 1;
|
|
} else if (story.style.display !== 'none') {
|
|
// we must decide either to hide or to count
|
|
if (!protection) {
|
|
story.style.display = 'none';
|
|
} else {
|
|
hidden = 1;
|
|
}
|
|
}
|
|
return hidden;
|
|
}
|
|
// magic filtering
|
|
|
|
function cleanTicker() {
|
|
//var ticker = document.getElementById('pagelet_ticker');
|
|
var tickerStories;
|
|
var story_idx;
|
|
var story;
|
|
var visibleCount;
|
|
var tickerLimit;
|
|
|
|
tickerLimit = 11;
|
|
visibleCount = 0;
|
|
console.log('begin com.facebook.cleanticker');
|
|
tickerStories = document.getElementsByClassName('fbFeedTickerStory');
|
|
for (story_idx = tickerStories.length - 1; story_idx >= 0; story_idx--) {
|
|
story = tickerStories.item(story_idx); //.children[0];
|
|
visibleCount += cleanStory(story, (visibleCount >= tickerLimit));
|
|
}
|
|
//for (story_idx = 0 ; story_idx < tickerStories.length; story_idx++) {
|
|
//story = tickerStories.item(story_idx); //.children[0];
|
|
//
|
|
//visibleCount += cleanStory(story, (visibleCount >= tickerLimit));
|
|
//}
|
|
//console.log('end com.facebook.tickerfilter.cleanTicker');
|
|
// send scrolldown events to ticker...
|
|
|
|
console.log('end com.facebook.cleanticker');
|
|
}
|
|
window.setInterval(cleanTicker, 1000);
|
|
window.setInterval(scrollTicker, 300);
|
|
}());
|
|
|