Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Gumtree Filter
- // @namespace garet.to.koks.pl
- // @version 0.1
- // @description filtr wynikow zapytan gumtree
- // @author Bartek Pawlowski, Garet
- // @match www.gumtree.pl/*
- // @grant GM_setValue
- // @grant GM_getValue
- // @require http://userscripts-mirror.org/scripts/source/107941.user.js
- // ==/UserScript==
- var contextURL = window.location.pathname;
- var contexts = new String(contextURL.split('/'));
- contexts = contexts.substring(1, contexts.length).split(',');
- console.log('contextURL: ' + contextURL);
- console.log('contexts: ' + contexts);
- if (contexts.length == 0) {
- return;
- }
- var blackListCategory = contexts[0];
- if (!blackListCategory) {
- return;
- }
- console.log('currentCategory: ' + blackListCategory);
- var blackList = GM_SuperValue.get(blackListCategory);
- if (blackList === null || blackList === undefined) {
- blackList = [];
- }
- GM_SuperValue.set(blackListCategory, blackList);
- console.log('Current blackListed items: ');
- console.log(blackList);
- function removeElementFromArray(inputArray, element){
- var elementIndex = inputArray.indexOf(element);
- if(elementIndex > -1){
- inputArray.splice(elementIndex, 1);
- }
- };
- function arrayContainsElement(inputArray, element) {
- for (var i = 0; i < inputArray.length; i++) {
- var arrayElem = inputArray[i];
- if (element.indexOf(arrayElem) > -1 || arrayElem.indexOf(element) > -1) {
- return true;
- }
- }
- return false;
- };
- function clearBlackList(blackListCategory) {
- blackList = [];
- GM_SuperValue.set(blackListCategory, blackList);
- }
- function createButton(buttonName, onClickListener) {
- var button = document.createElement('BUTTON');
- button.appendChild(document.createTextNode(buttonName));
- button.onclick = onClickListener;
- button.href = "";
- return button;
- };
- function getHyperLinkFromElement(element) {
- var potentialLinkElements = element.getElementsByClassName('adLinkSB');
- var linkElement = potentialLinkElements[0];
- if (linkElement !== null && linkElement !== undefined) {
- return linkElement.href;
- } else {
- return null;
- }
- };
- function addBlackListButton(element) {
- if (element !== null && element !== undefined) {
- element.appendChild(createButton('czarnolisto!', function () {
- var hyperLink = getHyperLinkFromElement(element);
- //dodajemy do czarnolisto
- addElementToBlackList(hyperLink);
- //usuwamy z DOMa
- element.parentElement.removeChild(element);
- }));
- }
- };
- function addElementToBlackList(element){
- blackList.push(element);
- GM_SuperValue.set(blackListCategory, blackList);
- if(blackListWindow != null){
- blackListWindow.onBlackListItemAdded(element);
- }
- };
- function removeElementFromBlackList(element){
- removeElementFromArray(blackList, element);
- GM_SuperValue.set(blackListCategory, blackList);
- };
- function addBlackListButtons() {
- var imageContainers = document.getElementsByClassName('ar-image');
- for (var i = 0; i < imageContainers.length; i++) {
- var imageContainer = imageContainers[i];
- addBlackListButton(imageContainer.parentElement.parentElement);
- }
- };
- function checkIfShouldBeRemoved(parent) {
- var potentialLinkElements = parent.getElementsByClassName('adLinkSB');
- var linkElement = potentialLinkElements[0];
- if (linkElement !== null && linkElement !== undefined) {
- return arrayContainsElement(blackList, linkElement.href);
- }
- return false;
- };
- //Matchuje elementy z DOMa z blackLista
- function getBlackListedEntries() {
- var resultSet = document.getElementsByClassName('resultsTableSB');
- var childrenToRemove = [];
- for (var i = 0; i < resultSet.length; i++) {
- var resultContainer = resultSet[i];
- if (checkIfShouldBeRemoved(resultContainer)) {
- childrenToRemove.push(resultContainer);
- }
- }
- return childrenToRemove;
- };
- //usuwa dodane do czarnej listy elementy
- function removeBlackListedEntries(childrenToRemove) {
- for (var i = 0; i < childrenToRemove.length; i++) {
- var element = childrenToRemove[i];
- element.parentElement.removeChild(element);
- }
- };
- function clearAds() {
- //usuniecie gornej reklamy adsense
- var adSenseContent = document.getElementById('topAdSense');
- adSenseContent.parentElement.removeChild(adSenseContent);
- //usuniecie dolnej reklamy adsense
- adSenseContent = document.getElementById('bottomAdSense');
- adSenseContent.parentElement.removeChild(adSenseContent);
- };
- var blackListWindow;
- function openBlackListWindow() {
- blackListWindow = window.open('', '', 'width=450, height=300');
- blackListWindow.document.title = 'Czarnolisto dla: ' + blackListCategory;
- blackListWindow.onbeforeunload = function(){
- blackListWindow = null;
- alert('Pamietaj aby przeladowac strone!');
- };
- blackListWindow.scrollableContainer = blackListWindow.document.createElement('div');
- blackListWindow.scrollableContainer.overflowY = 'scrollable';
- blackListWindow.document.body.appendChild(blackListWindow.scrollableContainer);
- blackListWindow.onBlackListItemAdded = function(blackListedURL){
- blackListWindow.addBlackListItem(blackListedURL);
- };
- blackListWindow.addBlackListItem = function(blackListItem){
- var blackListItemContainer = document.createElement('div');
- blackListItemContainer.id=blackListItem;
- var button = createButton('X', null);
- button.onclick = function (mouseEvent) {
- var srcButton = mouseEvent.srcElement;
- removeElementFromBlackList(srcButton.valueContainer.blackListItem);
- blackListWindow.scrollableContainer.removeChild(srcButton.valueContainer.blackListItemContainer);
- };
- button.valueContainer = {
- blackListItem: blackListItem,
- blackListItemContainer: blackListItemContainer
- };
- button.style.cssFloat = 'left';
- button.style.marginRight = "15px";
- var textDiv = blackListWindow.document.createElement('div');
- textDiv.innerHTML = blackListItem;
- textDiv.overflowX = 'hidden';
- textDiv.title = blackListItem;
- textDiv.style.maxWidth = '350px';
- textDiv.style.whiteSpace = 'nowrap';
- blackListItemContainer.appendChild(button);
- blackListItemContainer.appendChild(textDiv);
- blackListItemContainer.appendChild(blackListWindow.document.createElement('br'));
- blackListWindow.scrollableContainer.appendChild(blackListItemContainer);
- };
- var currBlackList = GM_SuperValue.get(blackListCategory);
- for (var i = 0; i < currBlackList.length; i++) {
- var blackListItem = currBlackList[i];
- blackListWindow.addBlackListItem(blackListItem);
- }
- };
- function addOpenBlackListWindowButton() {
- var manageBlackListButton = createButton('pokaz czarnolisto', function () {
- openBlackListWindow();
- });
- var mainContainer = document.getElementById("main");
- mainContainer.insertBefore(manageBlackListButton, mainContainer.children[0]);
- };
- $(document).ready(function () {
- // alert('Skrypt filtrowania jest uruchomiony. Wyniki na stronie sÄ… filtrowane!');
- //czysci reklamy adsense
- clearAds();
- //dodaje przuciski "czarnolisto"
- addBlackListButtons();
- //dodaje przycisk "pokaz czarnolisto"
- addOpenBlackListWindowButton();
- //poszukuje elementow z DOMa w czarnolisto i zwraca je tutaj
- var childrenToRemove = getBlackListedEntries();
- //usuniecie z DOMa wszystkich odnalezionych elementow w czarnolisto
- removeBlackListedEntries(childrenToRemove);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement