/*
* This file is part of Adblock Plus
,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see
.
*/
"use strict";
if (document instanceof HTMLDocument)
{
document.addEventListener("click", event =>
{
// Ignore right-clicks
if (event.button == 2)
return;
// Ignore simulated clicks.
if (event.isTrusted == false)
return;
// Search the link associated with the click
let link = event.target;
while (!(link instanceof HTMLAnchorElement))
{
link = link.parentNode;
if (!link)
return;
}
let queryString = null;
if (link.protocol == "http:" || link.protocol == "https:")
{
if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
queryString = link.search.substr(1);
}
else
{
// Firefox 51 doesn't seem to populate the "search" property for
// links with non-standard URL schemes so we need to extract the query
// string manually.
let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
if (match)
queryString = match[1];
}
if (!queryString)
return;
// This is our link - make sure the browser doesn't handle it
event.preventDefault();
event.stopPropagation();
// Decode URL parameters
let title = null;
let url = null;
for (let param of queryString.split("&"))
{
let parts = param.split("=", 2);
if (parts.length != 2 || !/\S/.test(parts[1]))
continue;
switch (parts[0])
{
case "title":
title = decodeURIComponent(parts[1]);
break;
case "location":
url = decodeURIComponent(parts[1]);
break;
}
}
if (!url)
return;
// Default title to the URL
if (!title)
title = url;
// Trim spaces in title and URL
title = title.trim();
url = url.trim();
if (!/^(https?|ftp):/.test(url))
return;
ext.backgroundPage.sendMessage({
type: "subscriptions.add",
title,
url,
confirm: true
});
}, true);
}
/*
* This file is part of Adblock Plus
,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see
.
*/
/* globals checkCollapse, elemhide, getURLsFromElement, typeMap */
"use strict";
// The page ID for the popup filter selection dialog (top frame only).
let blockelementPopupId = null;
// Element picking state (top frame only).
let currentlyPickingElement = false;
let lastMouseOverEvent = null;
// During element picking this is the currently highlighted element. When
// element has been picked this is the element that is due to be blocked.
let currentElement = null;
// Highlighting state, used by the top frame during element picking and all
// frames when the chosen element is highlighted red.
let highlightedElementsSelector = null;
let highlightedElementsInterval = null;
// Last right click state stored for element blocking via the context menu.
let lastRightClickEvent = null;
let lastRightClickEventIsMostRecent = false;
/* Utilities */
function getFiltersForElement(element, callback)
{
let src = element.getAttribute("src");
ext.backgroundPage.sendMessage({
type: "composer.getFilters",
tagName: element.localName,
id: element.id,
src: src && src.length <= 1000 ? src : null,
style: element.getAttribute("style"),
classes: Array.prototype.slice.call(element.classList),
urls: getURLsFromElement(element),
mediatype: typeMap.get(element.localName),
baseURL: document.location.href
},
response =>
{
callback(response.filters, response.selectors);
});
}
function getBlockableElementOrAncestor(element, callback)
{
// We assume that the user doesn't want to block the whole page.
// So we never consider the or element.
while (element && element != document.documentElement &&
element != document.body)
{
// We can't handle non-HTML (like SVG) elements, as well as
//
elements (see below). So fall back to the parent element.
if (!(element instanceof HTMLElement) || element.localName == "area")
element = element.parentElement;
// If image maps are used mouse events occur for the
element.
// But we have to block the image associated with the
Komentar
Posting Komentar