Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plug-in for: Google Sheets #800

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,11 @@
"js": ["plugins/duckduckgo.js"],
"matches": ["*://*.duckduckgo.com/*"
]
},
{
"js": ["plugins/googlesheets.js"],
"matches": ["*://docs.google.com/spreadsheets/*"
]
}
]
}
20 changes: 14 additions & 6 deletions plugins/duckduckgo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'duckduckgo',
version:'1.0',
version:'1.1',
prepareImgLinks:function (callback) {

var res = [];
var DDGData = null;
var DDGDataLowerCase = null;
var DDGDataJson = {};

// This script is injected into DDG results page in order to gain access to DDG internal data
Expand Down Expand Up @@ -96,7 +97,7 @@ hoverZoomPlugins.push({
// Find value(s) in JSON object and return corresponding key(s) and path(s)
// If value not found then return []
// ref: https://gist.github.com/killants/569c4af5f2983e340512916e15a48ac0
function getValuesInObject(jsonObj, searchValue, isRegex, isPartialMatch, maxDeepLevel, currDeepLevel) {
function getValuesInObject(jsonObj, searchValue, isRegex, isPartialMatch, isFirstMatchOnly, maxDeepLevel, currDeepLevel) {

var bShowInfo = false;

Expand All @@ -113,6 +114,8 @@ hoverZoomPlugins.push({
cLog(e);
return [];
}
} else {
searchValue = searchValue.toString().toLowerCase();
}

if ( currDeepLevel > maxDeepLevel ) {
Expand All @@ -130,22 +133,23 @@ hoverZoomPlugins.push({

if ( typeof currElem == "object" ) { // object is "object" and "array" is also in the eyes of "typeof"
// search again :D
var deepKeys = getValuesInObject( currElem, searchValue, isRegex, isPartialMatch, maxDeepLevel, currDeepLevel + 1 );
var deepKeys = getValuesInObject( currElem, searchValue, isRegex, isPartialMatch, isFirstMatchOnly, maxDeepLevel, currDeepLevel + 1 );
for ( var e = 0; e < deepKeys.length; e++ ) {
// update path backwards
deepKeys[e].path = '["' + curr + '"]' + deepKeys[e].path;
keys.push( deepKeys[e] );
}
} else {

if ( isRegex ? re.test(currElem) : ( isPartialMatch ? currElem.toString().toLowerCase().indexOf(searchValue.toString().toLowerCase()) != -1 : currElem.toString().toLowerCase() === searchValue.toString().toLowerCase() ) ){
if ( isRegex ? re.test(currElem) : ( isPartialMatch ? currElem.toString().toLowerCase().indexOf(searchValue) != -1 : currElem.toString().toLowerCase() === searchValue ) ){

var r = {};
r.key = curr;
r.value = currElem;
r.path = '["' + curr + '"]';
r.depth = currDeepLevel;
keys.push( r );
if (isFirstMatchOnly) return keys;
}
}
}
Expand Down Expand Up @@ -187,12 +191,16 @@ hoverZoomPlugins.push({
if (!DDGData) {

DDGData = sessionStorage.getItem('DDGData');
DDGDataLowerCase = DDGData.toString().toLowerCase();
try {
DDGDataJson = JSON.parse(DDGData);
} catch {}
}
if (DDGDataJson) {
let values = getValuesInObject(DDGDataJson, thumbnail, false, true); // look for a partial match

if (DDGDataLowerCase.indexOf(thumbnail.toString().toLowerCase()) == -1) return;

let values = getValuesInObject(DDGDataJson, thumbnail, false, true, true); // look for a partial match & stop after 1st match
if (values.length == 0) return;
let o = getObjectFromPath(DDGDataJson, values[0].path.substring(0, values[0].path.lastIndexOf('[')));
if (o.image) {
Expand Down
15 changes: 15 additions & 0 deletions plugins/googlesheets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name: 'GoogleSheets',
version:'0.1',
prepareImgLinks: function (callback) {
var res = [];

$('a[href]').one('mouseover', function() {
let link = $(this);
link.data().hoverZoomSrc = [this.href];
callback(link, this.name);
hoverZoom.displayPicFromElement(link);
});
}
});
59 changes: 1 addition & 58 deletions plugins/qwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,6 @@ hoverZoomPlugins.push({
(document.head || document.documentElement).appendChild(fetchScript);
}

// Find key(s) in JSON object and return corresponding value(s) and path(s)
// If key not found then return []
// https://gist.github.com/killants/569c4af5f2983e340512916e15a48ac0
function getKeysInObject(jsonObj, searchKey, isRegex, maxDeepLevel, currDeepLevel) {

var bShowInfo = false;

maxDeepLevel = ( maxDeepLevel || maxDeepLevel == 0 ) ? maxDeepLevel : 100;
currDeepLevel = currDeepLevel ? currDeepLevel : 1 ;
isRegex = isRegex ? isRegex : false;

// check RegEx validity if needed
var re;
if (isRegex) {
try {
re = new RegExp(searchKey);
} catch (e) {
cLog(e);
return [];
}
}

if( currDeepLevel > maxDeepLevel ) {
return [];
} else {

var keys = [];

for(var curr in jsonObj) {
var currElem = jsonObj[curr];

if( currDeepLevel == 1 && bShowInfo ) { cLog("getKeysInObject : Looking property \"" + curr + "\" ") }

if( isRegex ? re.test(curr) : curr === searchKey ){
var r = {};
r.key = curr;
r.value = currElem;
r.path = '["' + curr + '"]';
r.depth = currDeepLevel;
keys.push( r );
}

if( typeof currElem == "object" ) { // object is "object" and "array" is also in the eyes of "typeof"
// search again :D
var deepKeys = getKeysInObject( currElem, searchKey, isRegex, maxDeepLevel, currDeepLevel + 1 );

for(var e = 0 ; e < deepKeys.length; e++) {
// update path backwards
deepKeys[e].path = '["' + curr + '"]' + deepKeys[e].path;
keys.push( deepKeys[e] );
}
}
}
return keys;
}
}

// Find value(s) in JSON object and return corresponding key(s) and path(s)
// If value not found then return []
// ref: https://gist.github.com/killants/569c4af5f2983e340512916e15a48ac0
Expand Down Expand Up @@ -133,7 +76,7 @@ hoverZoomPlugins.push({
for(var curr in jsonObj) {
var currElem = jsonObj[curr];

if( currDeepLevel == 1 && bShowInfo ) { cLog("getKeysInObject : Looking property \"" + curr + "\" ") }
if( currDeepLevel == 1 && bShowInfo ) { cLog("getValuesInObject : Looking property \"" + curr + "\" ") }

if( typeof currElem == "object" ) { // object is "object" and "array" is also in the eyes of "typeof"
// search again :D
Expand Down