Skip to content

Commit

Permalink
Beta 3
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNygaard committed Jan 15, 2020
1 parent 8045cf2 commit 70611d7
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 112 deletions.
2 changes: 1 addition & 1 deletion backgroundscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ browser.contextMenus.onClicked.addListener((info, tab) => {
targetId: info.targetElementId,
supportsDeepSearch: !!(info.targetElementId && info.modifiers), // "deep-search" supported in Firefox 63+
deepSearch: info.modifiers && info.modifiers.includes("Shift"),
deepSearchBigMinSize: options["deepSearchBigMinSize"],
deepSearchBiggerLimit: options["deepSearchBiggerLimit"],
frameId : info.frameId, // related to globalThis/window/frames ?
frameUrl : info.frameUrl
});
Expand Down
16 changes: 8 additions & 8 deletions contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function loadparseshow(imgrequest) {
let infosArr = [];

console.debug("request: " + JSON.stringify(imgrequest));
if (imgrequest.naturalWidth && imgrequest.supportsDeepSearch && !imgrequest.deepSearch && (imgrequest.naturalWidth * imgrequest.naturalHeight <= imgrequest.deepSearchBigMinSize)) { // forceLargerThanSize !!!!!
if (imgrequest.naturalWidth && imgrequest.supportsDeepSearch && !imgrequest.deepSearch && (imgrequest.naturalWidth * imgrequest.naturalHeight <= imgrequest.deepSearchBiggerLimit)) {
infosArr.push('Not the expected image? You can force xIFr to look for a larger image than this, by holding down Shift key when selecting xIFr in the context menu!');
}

Expand Down Expand Up @@ -199,7 +199,7 @@ function loadparseshow(imgrequest) {
}


var genericLargerThanSize = 10 * 10; // Just not relevant if that small
var deepSearchGenericLimit = 10 * 10; // Just not relevant if that small

function imageSearch(request, elem) {
console.debug("imageSearch(): Looking for img elements on/below " + elem.nodeName.toLowerCase());
Expand All @@ -208,14 +208,14 @@ function imageSearch(request, elem) {
if (elem.contains(img)) { // img is itself/elem or img is a "sub-node"
console.debug("Found image within target element! img.src=" + img.src + " and naturalWidth=" + img.naturalWidth + ", naturalHeight=" + img.naturalHeight);
// We could look for best match, or just continue with the first we find?
if (img.naturalWidth > 10) { // Can't remember why I made this check? Superfluous? We compare with genericLargerThanSize further down
if (img.naturalWidth > 10) { // Can't remember why I made this check? Superfluous? We compare with deepSearchGenericLimit further down
console.debug("Candidate!?");
let propDisplay = window.getComputedStyle(img, null).getPropertyValue('display'); // none?
let propVisibility = window.getComputedStyle(img, null).getPropertyValue('visibility'); // hidden?
// Maybe also look at computed opacity ??!
console.debug("PROPs! display=" + propDisplay + ", visibility=" + propVisibility);
if (img.naturalWidth && img.nodeName.toUpperCase() === 'IMG' && propDisplay !== 'none' && propVisibility !== 'hidden' ) {
if ((request.deepSearch && (img.naturalWidth * img.naturalHeight) > request.deepSearchBigMinSize) || (!request.deepSearch && (img.naturalWidth * img.naturalHeight) > genericLargerThanSize)) { // forceLargerThanSize
if ((request.deepSearch && (img.naturalWidth * img.naturalHeight) > request.deepSearchBiggerLimit) || (!request.deepSearch && (img.naturalWidth * img.naturalHeight) > deepSearchGenericLimit)) {
if (typeof candidate !== "undefined") {
console.debug("Compare img with candidate: " + img.naturalWidth * img.naturalHeight + " > " + candidate.naturalWidth * candidate.naturalHeight + "? - document.images.length = " + document.images.length);
if ((img.naturalWidth * img.naturalHeight) > (candidate.naturalWidth * candidate.naturalHeight)) {
Expand All @@ -239,7 +239,7 @@ function imageSearch(request, elem) {
image.naturalWidth = candidate.naturalWidth;
image.naturalHeight = candidate.naturalHeight;
image.supportsDeepSearch = request.supportsDeepSearch;
image.deepSearchBigMinSize = request.deepSearchBigMinSize;
image.deepSearchBiggerLimit = request.deepSearchBiggerLimit;
image.deepSearch = request.deepSearch;
image.source = candidate.nodeName.toLowerCase() + " element"; // 'img element';
image.context = request.nodeName + " element"; // (not really anything to de with found image)
Expand All @@ -258,14 +258,14 @@ function bgSearch(request, elem, bgSizes) {
console.debug("Looking for dimensions of BACKGROUND-IMAGE via " + JSON.stringify(bgSizes));
for (let bgSrc of bgImgs) {
let imgData = bgSizes.find(bg => bg.src === bgSrc);
if (imgData.width && ((request.deepSearch && ((imgData.width * imgData.height) > request.deepSearchBigMinSize)) || (!request.deepSearch && ((imgData.width * imgData.height) > genericLargerThanSize)))) { // forceLargerThanSize
if (imgData.width && ((request.deepSearch && ((imgData.width * imgData.height) > request.deepSearchBiggerLimit)) || (!request.deepSearch && ((imgData.width * imgData.height) > deepSearchGenericLimit)))) {
let image = {};
image.imageURL = bgSrc;
image.mediaType = 'image';
image.naturalWidth = imgData.width;
image.naturalHeight = imgData.height;
image.supportsDeepSearch = request.supportsDeepSearch;
image.deepSearchBigMinSize = request.deepSearchBigMinSize;
image.deepSearchBiggerLimit = request.deepSearchBiggerLimit;
image.deepSearch = request.deepSearch;
image.source = 'background-image of an element'; // probably elem.nodeName, but not for sure
image.context = request.nodeName + " element"; // (not really anything to de with found image)
Expand Down Expand Up @@ -332,7 +332,7 @@ if (typeof contentListenerAdded === 'undefined') {
image.imageURL = request.imageURL;
image.mediaType = 'image';
image.supportsDeepSearch = request.supportsDeepSearch; // false
image.deepSearchBigMinSize = request.deepSearchBigMinSize;
image.deepSearchBiggerLimit = request.deepSearchBiggerLimit;
image.deepSearch = request.deepSearch;
image.source = "img element";
image.context = request.nodeName + " element"; // (not really anything to de with found image)
Expand Down
2 changes: 1 addition & 1 deletion context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var context = (function Context() {
let defaults = {
dispMode: "defaultMode",
popupPos: "defaultPos",
deepSearchBigMinSize: 175 * 175, // forceLargerThanSize 30625 deepSearchBiggerLimit? // Go bigger than this when "force larger size" (shift-select in context menu - Firefox 63+ feature) to avoid overlayed icons and logos
deepSearchBiggerLimit: 175 * 175, // 30625 - Go bigger than this when "force larger size" (shift-select in context menu - Firefox 63+ feature) to avoid overlayed icons and logos
mlinkOSM: true,
mlinkGoogle: true,
mlinkBing: true,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "xIFr",
"version": "0.9.0",
"version": "0.9.1",
"default_locale": "en",

"description": "__MSG_extensionDescription__",
Expand Down
10 changes: 5 additions & 5 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>

<div id="xIFroptionspage">
<p style="float:right">xIFr version <span id="verstr"></span> "Beta 2"</p>
<p style="float:right">xIFr version <span id="verstr"></span> "Beta 3"</p>
<img src="/icons/xIFr-256.png" alt="xIFr" style="width:128px;height:auto;margin:-10px 0 0 0" />
<form id="xIFroptions">
<fieldset style="position:relative">
Expand Down Expand Up @@ -100,12 +100,12 @@
</fieldset>
<fieldset style="position:relative" id="deepSearchSettings">
<legend>&nbsp;Deep Search&nbsp;</legend>
<p><em>Deep Search</em> is the name given to the algorithm xIFr uses to find/guess which image you where thinking of when right-clicking on a webpage (No, it's not always as obvious as it may seem).</p>
<p><em>Deep Search</em> is the name given to the method xIFr uses to find/guess which image you where thinking of when right-clicking on a webpage (No, it's not always as obvious as it may seem).</p>
<p>A special <em>"force big" mode</em><b class="note up">*</b> of <em>Deep Search</em> makes it possible to ignore smaller images:</p>
<p>
<label for="deepSearchBigMinSize">Make "force big" image search ignore images up to </label>
<input type="text" id="deepSearchBigMinSize" required="required" minlength="2" maxlength="6" size="8" pattern="[1-9]\d+" />
squarepixels big (Equivalent to f.ex: <span id="deepSearchBigMinSizeEx"></span>px).
<label for="deepSearchBiggerLimit">Make "force big" image search ignore images up to </label>
<input type="text" id="deepSearchBiggerLimit" required="required" minlength="2" maxlength="6" size="8" pattern="[1-9]\d+" inputmode="numeric" />
squarepixels big (Equivalent to f.ex: <span id="deepSearchBiggerLimitEx"></span>px).
</p>
<p class="note"><b class="up">*</b>You initiate the "force big" image search by using shift-click to select xIFr in browser's context menu.</p>
</fieldset>
Expand Down
8 changes: 4 additions & 4 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function setDisplayMode(dispMode) {
}

function updateDeepSearchSize() {
var inp = document.getElementById("deepSearchBigMinSize");
var out = document.getElementById("deepSearchBigMinSizeEx");
var inp = document.getElementById("deepSearchBiggerLimit");
var out = document.getElementById("deepSearchBiggerLimitEx");
out.textContent = "";
var d = parseInt(inp.value);
if (!isNaN(d)) {
Expand All @@ -25,7 +25,7 @@ function saveOptions(e) {
context.setOptions({
dispMode: document.forms[0].dispMode.value,
popupPos: document.forms[0].popupPos.value,
deepSearchBigMinSize: document.querySelector("form#xIFroptions #deepSearchBigMinSize").value,
deepSearchBiggerLimit: document.querySelector("form#xIFroptions #deepSearchBiggerLimit").value,
mlinkOSM: document.querySelector("form#xIFroptions #mlinkOSM").checked,
mlinkGoogle: document.querySelector("form#xIFroptions #mlinkGoogle").checked,
mlinkBing: document.querySelector("form#xIFroptions #mlinkBing").checked,
Expand Down Expand Up @@ -60,7 +60,7 @@ function initializeOptionsPage() {
}
if (context.supportsDeepSearch()) {
document.body.classList.add("supportsDeepSearch");
document.getElementById("deepSearchBigMinSize").addEventListener("keyup", updateDeepSearchSize);
document.getElementById("deepSearchBiggerLimit").addEventListener("keyup", updateDeepSearchSize);
}
context.getOptions().then(handlerInitOptionsForm);
}
Expand Down
Loading

0 comments on commit 70611d7

Please sign in to comment.