diff --git a/gm_base/gm_base.user.js.RAW.js b/gm_base/gm_base.user.js.RAW.js index c91a9e2..7b2abf4 100644 --- a/gm_base/gm_base.user.js.RAW.js +++ b/gm_base/gm_base.user.js.RAW.js @@ -3,10 +3,6 @@ // --------------- // noinspection JSUnusedGlobalSymbols -/** - * List of all URLs which are known by this script. - */ -const knownSite = []; const CURR_HOST = document.location.host; let CURR_PORT = document.location.port; @@ -1046,6 +1042,69 @@ function gmEmptyObj(obj) { // --------------- // noinspection JSUnusedGlobalSymbols +class PagelinksClazz { + /** + * + * @param {string} link + * @param {string|string[]} linkText + */ + constructor(link, linkText) { + this.link = link; + if (!gmIsArray(linkText)) { + this.linkText = [linkText]; + } else { + this.linkText = linkText; + } + } +} + +class KnowSiteClazz { + /** + * @param {string|RegExp} site + */ + constructor(site) { + this.site = site; + } +} + +class KnowSiteFilterClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string} filter + * @param {string|RegExp} path + */ + constructor(site, filter, path) { + super(site); + this.filter = filter; + this.path = path; + } +} + +class KnowSiteExtClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string|RegExp} url + * @param {string|RegExp} search + * @param {string|RegExp} replace + * @param {string|RegExp} replaceLarge + * @param {number} withDownload + */ + constructor(site, url, search, replace, replaceLarge, withDownload) { + super(site); + this.url = url; + this.search = search; + this.replace = replace; + this.replace_large = replaceLarge; + this.withDownload = withDownload; + } +} + +/** + * List of all URLs which are known by this script. + * @type {KnowSiteFilterClazz[]|KnowSiteExtClazz[]} + */ +let knownSite = []; + /** * Minimum width of the preview. * @type {number} @@ -1061,18 +1120,23 @@ const maxWidth = 640; /** * Adds an url which should be known for the search. * - * @param filter - a predefined searchtext for that url - * @param site - the hostname as regular expression - * @param path - a path as regular expression (optional) + * @param {string} filter - a predefined searchtext for that url + * @param {string|RegExp} site - the hostname as regular expression + * @param {string|RegExp} path - a path as regular expression (optional) */ function gmAddSite(filter, site, path) { - if (knownSite) { - if (site && (site !== "")) { - const len = knownSite.length; - knownSite[len] = {}; - knownSite[len].site = site; - knownSite[len].filter = (filter != null ? filter : ".+"); - knownSite[len].path = (path != null ? path : ""); + if (gmIsArray(knownSite)) { + if (site && (site.length > 0)) { + knownSite.push(new KnowSiteFilterClazz( + site, + (filter != null ? filter : ".+"), + (path != null ? path : "")) + ); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].filter = (filter != null ? filter : ".+"); + // knownSite[len].path = (path != null ? path : ""); } } } @@ -1080,24 +1144,32 @@ function gmAddSite(filter, site, path) { /** * Adds a config for a known site. * - * @param site - a site pattern - * @param urlElem - a pattern for the html-element to search in the page - * @param urlSearch - a pattern to search inside the url of the html-element - * @param urlReplace - a literal which will used for replacing the urlSearch - * @param urlReplaceLarge - a literal which will used for replacing the urlSearch with a url for large images - * @param withDownload - 1=will add a download-link beneath the picture, else 0 + * @param {string|RegExp} site - a site pattern + * @param {string|RegExp} urlElem - a pattern for the html-element to search in the page + * @param {string|RegExp} urlSearch - a pattern to search inside the url of the html-element + * @param {string|RegExp} urlReplace - a literal which will used for replacing the urlSearch + * @param {string|RegExp} urlReplaceLarge - a literal which will used for replacing the urlSearch with a url for large images + * @param {number} withDownload - 1=will add a download-link beneath the picture, else 0 */ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withDownload) { - if (knownSite) { + if (gmIsArray(knownSite)) { if (site && site.length > 0) { - const len = knownSite.length; - knownSite[len] = {}; - knownSite[len].site = site; - knownSite[len].url = (urlElem != null ? urlElem : ".+"); - knownSite[len].search = (urlSearch != null ? urlSearch : ""); - knownSite[len].replace = (urlReplace != null ? urlReplace : ""); - knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); - knownSite[len].withDownload = (withDownload != null ? withDownload : 0); + knownSite.push(new KnowSiteExtClazz( + site, + (urlElem != null ? urlElem : ".+"), + (urlSearch != null ? urlSearch : ""), + (urlReplace != null ? urlReplace : ""), + (urlReplaceLarge != null ? urlReplaceLarge : ""), + (withDownload != null ? withDownload : 0) + )); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].url = (urlElem != null ? urlElem : ".+"); + // knownSite[len].search = (urlSearch != null ? urlSearch : ""); + // knownSite[len].replace = (urlReplace != null ? urlReplace : ""); + // knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); + // knownSite[len].withDownload = (withDownload != null ? withDownload : 0); } } } @@ -1107,32 +1179,31 @@ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withD * predefined searchtext. If multiple sites will match, the LAST matching * filter will be returned. * - * @param site - the hostname of the site to search for - * @param path - the path of the site to search for (optional) + * @param {string} site - the hostname of the site to search for + * @param {string} path - the path of the site to search for (optional) * @returns {string} the predefined searchtext */ function gmFoundFilter(site, path) { let retFilter = ""; - let init = 0; - if (knownSite && site) { + if (gmIsArray(knownSite) && site) { if (!path) { path = ""; } - // alert("site: " + site + "| path: " + path); - for (let i = 0; i < knownSite.length; i++) { - // alert("u:" + knownSite[i].site+" p:" + knownSite[i].path); - if (site.search(knownSite[i].site) >= 0) { - if (init === 0 && knownSite[i].path === "") { - retFilter = knownSite[i].filter; + //for (let i = 0; i < knownSite.length; i++) { + let init = 0; + for (let currSite of knownSite) { + //let currSite = knownSite[i]; + if (site.search(currSite.site) >= 0) { + if (init === 0 && currSite.path === "") { + retFilter = currSite.filter; init = 1; } - const fIdx = path.search(knownSite[i].path); - //alert(fIdx + " u:>" + knownSite[i].site + "< p:>" + path + "< k:>"+knownSite[i].path + "<"); + let fIdx = path.search(currSite.path); if (path !== "" && (fIdx >= 0)) { - retFilter = knownSite[i].filter; + retFilter = currSite.filter; break; - } else if (path === "" && knownSite[i].path === "") { - retFilter = knownSite[i].filter; + } else if (path === "" && currSite.path === "") { + retFilter = currSite.filter; break; } } @@ -1144,24 +1215,36 @@ function gmFoundFilter(site, path) { /** * Searchs in the list of known sites, if this site is found and returns the predefined searchtext. If multiple sites will match, the LAST matching site will be returned. * - * @param site - the hostname of the site to search for - * @return a pattern for the html-element to search in the page + * @param {string} site - the hostname of the site to search for + * @return {KnowSiteExtClazz} a found site configuration */ function gmFoundFilter2(site) { let retFilter = null; - if (knownSite != null && site != null) { - for (let i = 0; i < knownSite.length; i++) { - if (site.search(knownSite[i].site) >= 0) { - retFilter = knownSite[i]; + if (gmIsArray(knownSite) && site) { + for (let currSite of knownSite) { + if (site.search(currSite.site) >= 0) { + retFilter = currSite; } } + //for (let i = 0; i < knownSite.length; i++) { + // if (site.search(knownSite[i].site) >= 0) { + // retFilter = knownSite[i]; + //} } return retFilter; } +/** @type {string} */ const FL_TAG = "result-list"; +/** @type {string} */ const FL_ID = "_FL"; +/** + * + * @param {string|HTMLElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkData(curlink, withDesc) { const linkData = []; linkData.push(gmGetAtI(curlink, "href")); @@ -1176,6 +1259,12 @@ function gmPrepareLinkData(curlink, withDesc) { return linkData; } +/** + * + * @param {string|HTMLAnchorElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkTextData(curlink, withDesc) { let linkTextData = []; try { @@ -1206,6 +1295,11 @@ function gmPrepareLinkTextData(curlink, withDesc) { return linkTextData; } +/** + * + * @param {string} searchPattern + * @return {RegExp} + */ function gmPrepareSearchRegExp(searchPattern) { if (!searchPattern || searchPattern.length <= 0) { searchPattern = ".*"; @@ -1216,52 +1310,47 @@ function gmPrepareSearchRegExp(searchPattern) { searchPattern = searchPattern.replace(/\?/g, ".").replace(/\./g, "\.").replace(/\*/g, ".*"); } //alert(searchPattern); - searchPattern = new RegExp(searchPattern, "i"); - return searchPattern; + return new RegExp(searchPattern, "i"); } /** * Search for all matching links in the page. * - * @param searchPattern - the search pattern or leave "" to get all - * @param withDesc - 0 = search only in links, + * @param {string} searchPattern - the search pattern or leave "" to get all + * @param {number} withDesc - 0 = search only in links, * 1 = search also in link description - * @returns {array} an array with all found links + * @returns {PagelinksClazz[]} an array with all found links */ function gmFindLinksInPage(searchPattern, withDesc) { let pagelinks = []; - if (withDesc == null) { + if (!withDesc) { withDesc = 0; } if (bTestMode) { pagelinks = gmGenTestEntries(40); } else { - searchPattern = gmPrepareSearchRegExp(searchPattern); - for (let i = 0; i < document.links.length; i++) { - let curlink = document.links[i]; - let ne = -1; - const searchParamLink = gmPrepareLinkData(curlink, withDesc); - const found = gmLinkMatchesPattern(searchParamLink, searchPattern); - if (found) { - if (gmGetAtI(curlink.id, FL_TAG) !== FL_ID) { - const htmllink = gmGetAtI(curlink, "href"); - const searchParamText = gmPrepareLinkTextData(curlink, withDesc); - const htmltext = gmLinkGenerateLinkText(searchParamText); - for (let j = 0; j < pagelinks.length; j++) { - if (htmllink === pagelinks[j][0]) { - ne = j; - break; - } - } - if (ne > -1) { - pagelinks[ne][1].push(htmltext); - pagelinks[ne][1] = gmOnlyUnique(pagelinks[ne][1]); - //alert(pagelinks[ne][1]); - } else { - curlink = [htmllink, [htmltext]]; - pagelinks.push(curlink); + //searchPattern = gmPrepareSearchRegExp(searchPattern); + //for (let linksIdx = 0; linksIdx < document.links.length; linksIdx++) { + for (let curLink of document.links) { + //let curLink = document.links[linksIdx]; + const found = gmLinkMatchesPattern(curLink, searchPattern, withDesc); + if (found && gmGetAtI(curLink.id, FL_TAG) !== FL_ID) { + let htmlLink = gmGetAtI(curLink, "href"); + let htmlText = gmLinkGenerateLinkText(curLink, withDesc); + let bFound = false; + for (let foundLinksIdx = 0; foundLinksIdx < pagelinks.length; foundLinksIdx++) { + let currPageLink = pagelinks[foundLinksIdx]; + if (htmlLink === currPageLink.link) { + bFound = true; + currPageLink.linkText.push(htmlText); + pagelinks[foundLinksIdx].linkText = gmOnlyUnique(currPageLink.linkText); + //alert(pagelinks[foundLinksIdx].linkText); + break; } } + if (!bFound) { + pagelinks.push(new PagelinksClazz(htmlLink, htmlText)); + } } } } @@ -1271,36 +1360,41 @@ function gmFindLinksInPage(searchPattern, withDesc) { /** * DON'T USE DIRECTLY * - * @param arrText - an array texts to search in - * @param searchPattern - a search text (might be a regular expression) + * @param {string|Object} curLink + * @param {string} searchPattern - a search text (might be a regular expression) + * @param {number} withDesc * @returns {boolean} TRUE= the search text is found in the array, or FALSE */ -function gmLinkMatchesPattern(arrText, searchPattern) { - let found = false; +function gmLinkMatchesPattern(curLink, searchPattern, withDesc) { + let cleanSearchPattern = gmPrepareSearchRegExp(searchPattern); + const arrText = gmPrepareLinkData(curLink, withDesc); + let bFound = false; if (gmIsArray(arrText)) { for (let i = 0; i < arrText.length; i++) { const searchText = arrText[i]; try { - found = searchText.search(searchPattern) !== -1; + bFound = searchText.search(cleanSearchPattern) !== -1; } catch (e) { // ignored } - if (found) { + if (bFound) { break; } } } - return found; + return bFound; } /** * DON'T USE DIRECTLY * - * @param arrText - an array with the possible link descriptions + * @param {string|Object} curLink + * @param {number} withDesc * @returns {string} the final link description */ -function gmLinkGenerateLinkText(arrText) { - const searchTextClean = []; +function gmLinkGenerateLinkText(curLink, withDesc) { + let arrText = gmPrepareLinkTextData(curLink, withDesc); + let searchTextClean = []; let htmlText = ""; if (gmIsArray(arrText)) { for (let idxST = 0; idxST < arrText.length; idxST++) { @@ -1314,7 +1408,7 @@ function gmLinkGenerateLinkText(arrText) { /** * Adds a javascript block into the page. * - * @param scc - a string, a function or an array with the javascript code or a function-list + * @param {Object|Function|Array|string} scc - a string, a function or an array with the javascript code or a function-list * @returns {boolean} TRUE = if the script block could be set, else FALSE */ function gmAddScriptGlobal(scc) { @@ -1343,7 +1437,7 @@ function gmAddScriptGlobal(scc) { /** * Adds a link to a javascript file into the page. * - * @param scLink - a string or an array with the url of the javascript-file + * @param {string|string[]} scLink - a string or an array with the url of the javascript-file * FIXME: Check */ function gmAddScriptLinkGlobal(scLink) { @@ -1370,7 +1464,7 @@ function gmAddScriptLinkGlobal(scLink) { /** * Adds a style block into the page. * - * @param scc - a string or an array with the css code + * @param {string|string[]} scc - a string or an array with the css code * @returns {boolean} TRUE = if the style block could be set, else FALSE */ function gmAddStyleGlobal(scc) { @@ -1399,11 +1493,11 @@ function gmAddStyleGlobal(scc) { /** * Generates some sample entries for testing. * - * @param maxEntries - number of entries to generate - * @returns {Array} array of entries + * @param {number} maxEntries - number of entries to generate + * @returns {PagelinksClazz[]} array of entries */ function gmGenTestEntries(maxEntries) { - if (isNaN(maxEntries) || maxEntries === "") { + if (isNaN(maxEntries)) { maxEntries = 1; } if (maxEntries < 0) { @@ -1413,10 +1507,9 @@ function gmGenTestEntries(maxEntries) { } let testArray = []; for (let i = 1; i <= maxEntries; i++) { - let htmllink = "https://" + currSite + currPath + "/link-" + i; - let htmltext = "linktext-" + i; - let curlink = [htmllink, htmltext]; - testArray.push(curlink); + let htmlLink = "https://" + currSite + currPath + "/link-" + i; + let htmlText = "linktext-" + i; + testArray.push(new PagelinksClazz(htmlLink, htmlText)); } return testArray; } @@ -1424,7 +1517,7 @@ function gmGenTestEntries(maxEntries) { /** * Calculate the offset of an element relating to the elemnt at the most top. * - * @param {Object} element - the element to check the offeset + * @param {Object|HTMLInputElement} element - the element to check the offeset * @returns {number[]} an array with the leftOffset, topOffset * FIXME:TEST */ @@ -1445,9 +1538,9 @@ function gmCumulativeOffset(element) { /** * Calculates the horizontal offset to the right in relation to it's parent element. * - * @param parentElem - the element to calculate the offset from - * @param iPoint - a screen point, to add an additional offset - * @param iZoom - the zoom factor 1= Originalsize + * @param {Object} parentElem - the element to calculate the offset from + * @param {Array} iPoint - a screen point, to add an additional offset + * @param {number} iZoom - the zoom factor 1= Originalsize * @returns {number} the horizontal offset or 0 FIXME:Test */ function gmCalcOffsetH(parentElem, iPoint, iZoom) { @@ -1469,9 +1562,9 @@ function gmCalcOffsetH(parentElem, iPoint, iZoom) { /** * Searches the url for a pattern and replace the text. * - * @param searchForPattern - the pattern to search for - * @param replaceWithText - the text what will be inserted instead - * @param oldUrl - the URL to search in + * @param {string} searchForPattern - the pattern to search for + * @param {string} replaceWithText - the text what will be inserted instead + * @param {string} oldUrl - the URL to search in * @returns {string} the url with replaced text */ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { @@ -1492,7 +1585,7 @@ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { /** * Returns the actual server of the running page. * - * @returns a server name + * @returns {string} a server name */ function gmGetCurrentSite() { let currSite = document.location.host; @@ -1531,12 +1624,12 @@ function gmGetImageSize(newImage) { /** * Add a default style to a div-element. * - * @param hDiv - the div-element - * @param iPoint - metrics of the image [width, height] in px - * @param offsetW - an offset (number) for the width (optional), default is 5px - * @param offsetH - an offset (number) for the height (optional), default is 5px - * @param ratio - the aspect ratio of the image, only is used, if we have no image height - * @param iZoom - + * @param {Object} hDiv - the div-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} offsetW - an offset (number) for the width (optional), default is 5px + * @param {number} offsetH - an offset (number) for the height (optional), default is 5px + * @param {number} ratio - the aspect ratio of the image, only is used, if we have no image height + * @param {number} iZoom - * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { @@ -1591,11 +1684,11 @@ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { /** * Add a default style to an img-element. * - * @param hDiv - the div-element - * @param hImg - the img-element - * @param iPoint - metrics of the image [width, height] in px - * @param iZoom - the zoom factor (1 = Originalsize) - * @returns {Boolean} TRUE = the layout could be added, else FALSE + * @param {Object} hDiv - the div-element + * @param {Object} hImg - the img-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} iZoom - the zoom factor (1 = Originalsize) + * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { let h = "auto"; @@ -1637,7 +1730,6 @@ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { gmSetAtI(hDiv, "style", css); isSet = true; } - return isSet; } @@ -1658,7 +1750,7 @@ function gmGetBody() { } /** - * @param obj - the object from which to get the css-style + * @param {string|Object} obj - the object from which to get the css-style * @returns {Object} the css-style-object from that object */ function gmGetStyle(obj) { @@ -1693,6 +1785,11 @@ function gmGetBodyHeight() { return Math.max(Dh, Eh); } +/** + * + * @param {string} url + * @return {boolean} + */ function gmOpenInTab(url) { if (url) { window.open(url, "_blank"); diff --git a/gm_base/gm_base.user.js.RAW.js.prev b/gm_base/gm_base.user.js.RAW.js.prev index 02e998b..7b2abf4 100644 --- a/gm_base/gm_base.user.js.RAW.js.prev +++ b/gm_base/gm_base.user.js.RAW.js.prev @@ -1,41 +1,33 @@ // --------------- // base-core.js - START // --------------- +// noinspection JSUnusedGlobalSymbols -/** - * List of all URLs which are known by this script. - */ -var knownSite = []; -var currHost = document.location.host; -var currPort = document.location.port; +const CURR_HOST = document.location.host; +let CURR_PORT = document.location.port; /** * The URL we are currently running on. */ -var currSite = currHost; +let currSite = CURR_HOST; if (document.location.port) { - currPort = ":" + document.location.port; - if (currSite.search(currPort) == -1) { + CURR_PORT = ":" + document.location.port; + if (currSite.search(CURR_PORT) === -1) { currSite += ":" + document.location.port; } } -var currPath = document.location.href.substring(document.location.href - .indexOf(currSite) - + currSite.length); - -var bTestMode = false; - -var INIT_ONLOAD = true; +const currPath = document.location.href.substring(document.location.href.indexOf(currSite) + currSite.length); +const bTestMode = false; +const INIT_ONLOAD = true; // - General DHTML-Lib - Start // - modified & extended dhtml.js from selfhtml.de -var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false; - -var shortId = "id"; +let DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false; -var ATTR_SEP = ";"; +const SHORT_ID = "id"; +const ATTR_SEP = ";"; if (document.getElementById) { DHTML = true; @@ -64,7 +56,7 @@ if (window.opera) { * @returns {Object} the found object or null */ function gmGetElI(identifier) { - return gmGetEl(shortId, identifier, null); + return gmGetEl(SHORT_ID, identifier, null); } /** @@ -79,7 +71,7 @@ function gmGetElI(identifier) { * @returns {Object} the found object or null */ function gmGetEl(mode, identifier, elementNumber) { - var element, elementList; + let element, elementList; if (gmIsObject(identifier)) { return identifier; } @@ -92,21 +84,22 @@ function gmGetEl(mode, identifier, elementNumber) { } else { alert(null); } + return null; } if (DOM) { - if (mode.toLowerCase() == "id") { + if (mode.toLowerCase() === "id") { element = document.getElementById(identifier); return element; } - if (mode.toLowerCase() == "name") { + if (mode.toLowerCase() === "name") { elementList = document.getElementsByName(identifier); element = elementList[elementNumber]; - if (!element || element == "undefined") { + if (!element || element === "undefined") { element = null; } return element; } - if (mode.toLowerCase() == "tagname") { + if (mode.toLowerCase() === "tagname") { elementList = document.getElementsByTagName(identifier); element = elementList[elementNumber]; return element; @@ -114,11 +107,11 @@ function gmGetEl(mode, identifier, elementNumber) { return null; } if (MSIE4) { - if (mode.toLowerCase() == "id" || mode.toLowerCase() == "name") { + if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") { element = document.all(identifier); return element; } - if (mode.toLowerCase() == "tagname") { + if (mode.toLowerCase() === "tagname") { elementList = document.all.tags(identifier); element = elementList[elementNumber]; return element; @@ -126,14 +119,14 @@ function gmGetEl(mode, identifier, elementNumber) { return null; } if (NS4) { - if (mode.toLowerCase() == "id" || mode.toLowerCase() == "name") { + if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") { element = document[identifier]; if (!element) { element = document.anchors[identifier]; } return element; } - if (mode.toLowerCase() == "layerindex") { + if (mode.toLowerCase() === "layerindex") { element = document.layers[identifier]; return element; } @@ -159,20 +152,19 @@ function gmGetElList(mode, identifier) { return null; } if (DOM) { - if (mode.toLowerCase() == "name") { + if (mode.toLowerCase() === "name") { return document.getElementsByName(identifier); } - if (mode.toLowerCase() == "tagname") { + if (mode.toLowerCase() === "tagname") { return document.getElementsByTagName(identifier); } return null; } if (MSIE4) { - if (mode.toLowerCase() == "id" || mode.toLowerCase() == "name") { - element = document.all(identifier); - return element; + if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") { + return document.all(identifier); } - if (mode.toLowerCase() == "tagname") { + if (mode.toLowerCase() === "tagname") { return document.all.tags(identifier); } return null; @@ -193,7 +185,7 @@ function gmGetElList(mode, identifier) { * @returns {Object} returns the found attribute or false */ function gmGetAtI(identifier, attributeName) { - return gmGetAt(shortId, identifier, null, attributeName); + return gmGetAt(SHORT_ID, identifier, null, attributeName); } /** @@ -210,8 +202,8 @@ function gmGetAtI(identifier, attributeName) { * @returns {Object} returns the found attribute or null */ function gmGetAt(mode, identifier, elementNumber, attributeName) { - var attribute = null; - var element = gmGetEl(mode, identifier, elementNumber); + let attribute = null; + const element = gmGetEl(mode, identifier, elementNumber); if (element) { if (DOM || MSIE4) { try { @@ -242,7 +234,7 @@ function gmGetAt(mode, identifier, elementNumber, attributeName) { * @returns {Object} returns the found content or null */ function gmGetCoI(identifier) { - return gmGetCo(shortId, identifier, null); + return gmGetCo(SHORT_ID, identifier, null); } /** @@ -257,11 +249,11 @@ function gmGetCoI(identifier) { * @returns {Object} returns the found content or null */ function gmGetCo(mode, identifier, elementNumber) { - var content = null; - var element = gmGetEl(mode, identifier, elementNumber); + let content = null; + const element = gmGetEl(mode, identifier, elementNumber); if (element) { if (DOM && element.firstChild) { - if (element.firstChild.nodeType == 3) { + if (element.firstChild.nodeType === 3) { content = element.firstChild.nodeValue; } else { content = ""; @@ -286,7 +278,7 @@ function gmGetCo(mode, identifier, elementNumber) { * @returns {Boolean} TRUE=if set was successfull, else FALSE */ function gmSetCoI(identifier, text) { - return gmSetCo(shortId, identifier, null, text); + return gmSetCo(SHORT_ID, identifier, null, text); } /** @@ -303,7 +295,7 @@ function gmSetCoI(identifier, text) { * @returns {Boolean} TRUE=if set was successfull, else FALSE */ function gmSetCo(mode, identifier, elementNumber, text) { - var element = gmGetEl(mode, identifier, elementNumber); + const element = gmGetEl(mode, identifier, elementNumber); if (element) { if (DOM) { if (!element.firstChild) { @@ -325,6 +317,7 @@ function gmSetCo(mode, identifier, elementNumber, text) { } return false; } + // - General DHTML-Lib - End /** @@ -340,7 +333,7 @@ function gmSetCo(mode, identifier, elementNumber, text) { * @returns {Boolean} TRUE = the value could be set, else FALSE */ function gmSetAtI(identifier, attributeName, attributeValue) { - return gmSetAt(shortId, identifier, null, attributeName, attributeValue); + return gmSetAt(SHORT_ID, identifier, null, attributeName, attributeValue); } /** @@ -351,6 +344,7 @@ function gmSetAtI(identifier, attributeName, attributeValue) { * how the Identifier is interpreted (id, name, tagname) * @param identifier - * the key (id, name, tagname) of the element + * @param elementNumber * @param attributeName - * the unique name of the attribute * @param attributeValue - @@ -359,7 +353,7 @@ function gmSetAtI(identifier, attributeName, attributeValue) { */ function gmSetAt(mode, identifier, elementNumber, attributeName, attributeValue) { //var attribute; - var element = gmGetEl(mode, identifier, elementNumber); + const element = gmGetEl(mode, identifier, elementNumber); if (element) { if (DOM || MSIE4) { try { @@ -398,8 +392,8 @@ function gmSetAt(mode, identifier, elementNumber, attributeName, attributeValue) * @returns {Boolean} TRUE = the value could be set, else FALSE */ function gmAppAt(mode, identifier, attributeName, attributeValue) { - var oldValue = gmGetAt(mode, identifier, attributeName); - var newValue = oldValue + ATTR_SEP + attributeValue; + const oldValue = gmGetAt(mode, identifier, attributeName); + const newValue = oldValue + ATTR_SEP + attributeValue; return gmSetAt(mode, identifier, attributeName, newValue); } @@ -416,7 +410,7 @@ function gmAppAt(mode, identifier, attributeName, attributeValue) { * @returns {Boolean} TRUE = the value could be set, else FALSE */ function gmAppAtI(identifier, attributeName, attributeValue) { - return gmAppAt(shortId, identifier, attributeName, attributeValue); + return gmAppAt(SHORT_ID, identifier, attributeName, attributeValue); } /** @@ -437,6 +431,7 @@ function gmIsFunction(obj) { function gmIsUndefined(obj) { return (obj == null ? true : (typeof obj == "undefined")); } + /** * Verifies if an instance is an object. * @@ -458,14 +453,14 @@ function gmIsObject(obj) { * @returns {Boolean} TRUE = if the object is from the tested type, else FALSE */ function gmIsInstanceOf(obj, objType) { - var isType = false; + let isType = false; if (obj != null) { if (objType == null) { objType = "Object"; } try { - tObjType = eval(objType); - isType = (obj.constructor == tObjType); + let tObjType = eval(objType); + isType = (obj.constructor === tObjType); } catch (e) { // ignore } @@ -482,11 +477,11 @@ function gmIsInstanceOf(obj, objType) { * @returns {String} the trimmed string */ function ltrim(a) { - var ret = null; + let ret = null; if (a != null) { - ret = new String(a); - var pos = 0; - while (a.charAt(pos) == " ") { + ret = String(a); + let pos = 0; + while (a.charAt(pos) === " ") { pos++; } ret = a.substring(pos); @@ -502,11 +497,11 @@ function ltrim(a) { * @returns {String} the trimmed string */ function rtrim(a) { - var ret = null; + let ret = null; if (a != null) { - ret = new String(a); - var pos = a.length - 1; - while (a.charAt(pos) == " ") { + ret = String(a); + let pos = a.length - 1; + while (a.charAt(pos) === " ") { pos--; } ret = a.substring(0, pos + 1); @@ -526,7 +521,7 @@ function trim(a) { } function gmCleanText(dirtyText) { - var cleanText = ""; + let cleanText = ""; if (gmIsInstanceOf(dirtyText, String)) { cleanText = dirtyText.replace(/\s\s/g, "").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/#/g, ""); } @@ -541,11 +536,11 @@ function gmCleanText(dirtyText) { * @returns {Number} the found numeric value or 0; */ function gmToNo(a) { - var numFound = ""; + let numFound = ""; if (isNaN(a)) { if (a && a.length > 0) { - for ( var int = 0; int < a.length; int++) { - var a_ele = a[int]; + for (let int = 0; int < a.length; int++) { + const a_ele = a[int]; if (!isNaN(a_ele)) { numFound += a_ele; } else { @@ -555,17 +550,18 @@ function gmToNo(a) { } else { numFound = a; } - newNum = new Number(numFound).valueOf(); - if (typeof(newNum) != "number") { + let newNum = Number(numFound).valueOf(); + if (typeof (newNum) != "number") { newNum = 0; } return newNum; } -const SORT_NO = 0; +const SORT_NO = 0; const SORT_DEF = 1; const SORT_REV = 2; const SORT_NUM = 3; + /** * Sorts an array by a specific sort order (alphanumeric). * @@ -574,17 +570,17 @@ const SORT_NUM = 3; * @returns {Array} the sorted array */ function gmSortArray(unsortedArray, sortMode) { - var sortedArray = unsortedArray; + const sortedArray = unsortedArray; if (sortMode == null) { sortMode = false; } - if (sortMode == SORT_NUM) { - sortedArray.sort(function(aE, bE){ + if (sortMode === SORT_NUM) { + sortedArray.sort(function (aE, bE) { return aE - bE; }); - } else if (sortMode == SORT_REV) { + } else if (sortMode === SORT_REV) { sortedArray.reverse(); - } else if (sortMode || sortMode == SORT_DEF) { + } else if (sortMode || sortMode === SORT_DEF) { sortedArray.sort(); } return sortedArray; @@ -593,14 +589,20 @@ function gmSortArray(unsortedArray, sortMode) { function gmSortObject(unsortedObjects, sortField) { try { if (gmIsArray(unsortedObjects)) { - unsortedObjects.sort(function(aElem, bElem) { - var x = aElem[sortField].toLowerCase(); - var y = bElem[sortField].toLowerCase(); - if (x < y) {return -1;} - if (x > y) {return 1;} - return 0; - } - )}; + unsortedObjects.sort(function (aElem, bElem) { + const x = aElem[sortField].toLowerCase(); + const y = bElem[sortField].toLowerCase(); + if (x < y) { + return -1; + } + if (x > y) { + return 1; + } + return 0; + } + ); + } + } catch (ex) { alert(ex); } @@ -608,10 +610,10 @@ function gmSortObject(unsortedObjects, sortField) { } function gmOnlyUnique(arrArray) { - var arrUnique = []; + let arrUnique = []; if (gmIsArray(arrArray)) { arrUnique = arrArray.filter(function (value, index, self) { - return self.indexOf(value) === index; + return self.indexOf(value) === index; }); } return arrUnique; @@ -625,7 +627,7 @@ function gmOnlyUnique(arrArray) { * @returns {Boolean} TRUE = if all handler are succesfull done, else FALSE */ function gmAddHandler(e) { - var isDone = false; + let isDone; lgm_addKnownSites(); lgm_addStyles(); lgm_addControls(); @@ -634,13 +636,12 @@ function gmAddHandler(e) { return isDone; } - /** -* Now add the event handler. -*/ + * Now add the event handler. + */ function gmInitEventHandler() { if (INIT_ONLOAD) { - window.addEventListener("load", function(e) { + window.addEventListener("load", function (e) { gmAddHandler(e); }); } @@ -652,22 +653,20 @@ function gmInitEventHandler() { // --------------- // base-object.js - START // --------------- +// noinspection JSUnresolvedVariable,JSUnresolvedFunction,JSUnusedGlobalSymbols /** * Creates an DOM-Object. * - * @param par - - * the parent object to create the new object as child - * @param objtyp - - * the type of the new object (HTML-Tagname) - * @param id - - * the id and name of the new object + * @param par - the parent object to create the new object as child + * @param objtyp - the type of the new object (HTML-Tagname) + * @param id - the id and name of the new object * @returns {Object} the created object or null */ function gmCreateObj(par, objtyp, id) { // var obj = $("<" + objtyp + ">"); - var obj = null; - if (objtyp != null && objtyp != "") { + let obj = null; + if (objtyp != null && objtyp !== "") { obj = document.createElement(objtyp); if (obj) { if (id != null) { @@ -688,24 +687,15 @@ function gmCreateObj(par, objtyp, id) { /** * Create common attributes for an DOM-Object. Leave null if not used. * - * @param obj - - * the object to create the attributes in it - * @param caption - - * a text which will be displayed for this object - * @param tit - - * a W3C-conform title for that DOM - * @param ro - - * if set != null, the DOM will be readonly - * @param ev_click - - * a javascript-call for the click-event - * @param ev_focus - - * a javascript-call for the focus-event - * @param ev_mOver - - * a javascript-call for the mouseover-event - * @param ev_mOut - - * a javascript-call for the mouseout-event - * @param ev_dblClick - - * a javascript-call for the doubleclick-event + * @param obj - the object to create the attributes in it + * @param caption - a text which will be displayed for this object + * @param tit - a W3C-conform title for that DOM + * @param ro - if set != null, the DOM will be readonly + * @param ev_click - a javascript-call for the click-event + * @param ev_focus - a javascript-call for the focus-event + * @param ev_mOver - a javascript-call for the mouseover-event + * @param ev_mOut - a javascript-call for the mouseout-event + * @param ev_dblClick - a javascript-call for the doubleclick-event * @returns {Object} the object with added attributes FIXME: Check */ function gmCreateObjCommon(obj, caption, tit, ro, ev_click, ev_focus, ev_mOver, ev_mOut, ev_dblClick) { @@ -723,23 +713,28 @@ function gmCreateObjCommon(obj, caption, tit, ro, ev_click, ev_focus, ev_mOver, if (ev_click) { // obj.click(ev_click); obj.onclick = ev_click; - }; + } + if (ev_dblClick) { // obj.click(ev_dblClick); obj.ondblclick = ev_dblClick; - }; + } + if (ev_focus) { // obj.focus(ev_focus); obj.onfocus = ev_focus; - }; + } + if (ev_mOver) { // obj.hover(ev_mOver); obj.onmouseover = ev_mOver; - }; + } + if (ev_mOut) { // obj.hover(ev_mOut); obj.onmouseout = ev_mOut; - }; + } + } return obj; } @@ -747,24 +742,17 @@ function gmCreateObjCommon(obj, caption, tit, ro, ev_click, ev_focus, ev_mOver, /** * Creates a DOM-Button. * - * @param par - - * the parent object to create the new object as child - * @param typ - - * the type of the new object (HTML-Tagname) - * @param id - - * the id and name of the new object - * @param caption - - * a text which will be displayed for this object - * @param tit - - * a W3C-conform title for that DOM - * @param initval - - * an initial value is set in this input - * @param ev_click - - * a javascript-call for the click-event + * @param par - the parent object to create the new object as child + * @param typ - the type of the new object (HTML-Tagname) + * @param id - the id and name of the new object + * @param caption - a text which will be displayed for this object + * @param tit - a W3C-conform title for that DOM + * @param initval - an initial value is set in this input + * @param ev_click - a javascript-call for the click-event * @returns {Object} the created DOM-Button */ function gmCreateButton(par, typ, id, caption, tit, initval, ev_click) { - var obj = gmCreateObj(par, "button", id); + let obj = gmCreateObj(par, "button", id); obj = gmCreateObjCommon(obj, caption, tit, null, ev_click); if (!typ) { typ = "button"; @@ -779,22 +767,18 @@ function gmCreateButton(par, typ, id, caption, tit, initval, ev_click) { /** * Creates a DOM-Link. * - * @param par - - * the parent object to create the new object as child - * @param id - - * the id and name of the new object - * @param caption - - * a text which will be displayed for this object - * @param tit - - * a W3C-conform title for that DOM - * @param ev_click - - * a javascript-call for the click-event - * @param ev_dblClick - - * a javascript-call for the doubleclick-event + * @param par - the parent object to create the new object as child + * @param id - the id and name of the new object + * @param href + * @param caption - a text which will be displayed for this object + * @param tit - a W3C-conform title for that DOM + * @param target + * @param ev_click - a javascript-call for the click-event + * @param ev_dblClick - a javascript-call for the doubleclick-event * @returns {Object} the created DOM-Link */ function gmCreateLink(par, id, href, caption, tit, target, ev_click, ev_dblClick) { - var obj = gmCreateObj(par, "a", id); + let obj = gmCreateObj(par, "a", id); obj = gmCreateObjCommon(obj, caption, tit, null, ev_click, null, null, null, ev_dblClick); if (href) { gmSetAtI(obj, "href", href); @@ -810,26 +794,18 @@ function gmCreateLink(par, id, href, caption, tit, target, ev_click, ev_dblClick /** * Creates a DOM-Input-Element. * - * @param par - - * the parent object to create the new object as child - * @param typ - - * the type of the new input (Type-Attribute) - * @param id - - * the id and name of the new object - * @param initval - - * an initial value is set in this input - * @param tit - - * a W3C-conform title for that DOM - * @param ro - - * if set != null, the DOM will be readonly - * @param ev_click - - * a javascript-call for the click-event - * @param ev_focus - - * a javascript-call for the focus-event + * @param par - the parent object to create the new object as child + * @param typ - the type of the new input (Type-Attribute) + * @param id - the id and name of the new object + * @param initval - an initial value is set in this input + * @param tit - a W3C-conform title for that DOM + * @param ro - if set != null, the DOM will be readonly + * @param ev_click - a javascript-call for the click-event + * @param ev_focus - a javascript-call for the focus-event * @returns {Object} the new DOM-Input */ function gmCreateInput(par, typ, id, initval, tit, ro, ev_click, ev_focus) { - var obj = gmCreateObj(par, "input", id); + let obj = gmCreateObj(par, "input", id); if (obj) { obj = gmCreateObjCommon(obj, null, tit, ro, ev_click, ev_focus); if (!typ) { @@ -850,15 +826,13 @@ function gmCreateInput(par, typ, id, initval, tit, ro, ev_click, ev_focus) { /** * Adds an object as a child node to a parent object or the document body. * - * @param obj - - * the object to append at the end of the child list - * @param parent - - * the parent object to append to, leave null to put it to the + * @param obj - the object to append at the end of the child list + * @param parent - the parent object to append to, leave null to put it to the * document-body * @returns {Boolean} TRUE = the object could be added, else FALSE */ function gmAddObj(obj, parent) { - var isSet = false; + let isSet = false; if (gmIsObject(obj)) { if (!parent) { parent = gmGetEl("tagname", "body"); @@ -872,16 +846,14 @@ function gmAddObj(obj, parent) { /** * Sets a new value into an object. * - * @param id - - * the id of the object - * @param initval - - * the new value for that element or empty + * @param id - the id of the object + * @param initval - the new value for that element or empty * @returns {Boolean} TRUE = if the value could be set, else FALSE */ function gmSetInput(id, initval) { - var isSet = false; + let isSet = false; // var obj = document.getElementById(id); - var obj = gmGetElI(id); + const obj = gmGetElI(id); if (obj) { if (initval) { // obj.setAttribute("value", initval); @@ -899,12 +871,11 @@ function gmSetInput(id, initval) { /** * Selects the text in a input element. * - * @param inputElem - - * the element containing the text + * @param inputElem - the element containing the text * @returns {Boolean} TRUE = if the input element could be selected, else FALSE */ function gmSelectInput(inputElem) { - var isSet = false; + let isSet = false; if (gmIsObject(inputElem)) { try { inputElem.select(); @@ -918,11 +889,11 @@ function gmSelectInput(inputElem) { /** * Constants for Selection of Text using IE. */ -var SELECT_IE = 0; +const SELECT_IE = 0; /** * Constants for Selection of Text using Gecko Engine. */ -var SELECT_G = 1; +const SELECT_G = 1; /** * @returns {Number} which Selection of Text Modus is used @@ -935,12 +906,13 @@ function gmGetTextSelectMode() { } return SELECT_IE; } + /** * Constants Mode which is currently used for Selection of Text. * * @see {@link #gmGetTextSelectMode()} */ -var SELECT_CURR = gmGetTextSelectMode(); +const SELECT_CURR = gmGetTextSelectMode(); /** * Returns the selected Text or an empty String. @@ -948,10 +920,10 @@ var SELECT_CURR = gmGetTextSelectMode(); * @returns {String} the text which is currently selected. */ function gmGetSelectedText() { - var selectedText = ""; - if (SELECT_IE == SELECT_CURR) { + let selectedText = ""; + if (SELECT_IE === SELECT_CURR) { selectedText = document.selection.createRange().text; - } else if (SELECT_G == SELECT_CURR) { + } else if (SELECT_G === SELECT_CURR) { selectedText = window.getSelection(); } if (typeof selectedText == "object") { @@ -963,15 +935,14 @@ function gmGetSelectedText() { /** * Creates a new Range-Object for an element. * - * @param elem - - * an element for the Range-Object or null; + * @param elem - an element for the Range-Object or null; * @returns {Range} a new Range-Object or null */ function gmGetNewRange(elem) { - var textRange = null; - if (SELECT_IE == SELECT_CURR) { + let textRange = null; + if (SELECT_IE === SELECT_CURR) { textRange = document.selection.createRange(); - } else if (SELECT_G == SELECT_CURR) { + } else if (SELECT_G === SELECT_CURR) { if (gmIsObject(elem)) { textRange = document.createRange(); try { @@ -988,31 +959,31 @@ function gmGetNewRange(elem) { * Selects or Unselects the content inside an element (not only for input * elements. * - * @param elem - - * the element to select the text in it - * @param bForceSelect - - * TRUE=always select, FALSE=switch between select and unselect + * @param elem - the element to select the text in it + * @param bForceSelect - TRUE=always select, FALSE=switch between select and unselect * @returns {String} the selected text or an empty string */ function gmSelectText(elem, bForceSelect) { - var currSel = gmGetSelectedText(); + let selection; + let currSel = gmGetSelectedText(); if (bForceSelect == null) { bForceSelect = false; } - if (!bForceSelect && (currSel && currSel != "")) { - if (SELECT_IE == SELECT_CURR) { + if (!bForceSelect && (currSel && currSel !== "")) { + if (SELECT_IE === SELECT_CURR) { + // noinspection BadExpressionStatementJS document.selection.empty; - } else if (SELECT_G == SELECT_CURR) { - var selection = window.getSelection(); + } else if (SELECT_G === SELECT_CURR) { + selection = window.getSelection(); selection.removeAllRanges(); } } else { if (gmIsObject(elem)) { - var tRange = gmGetNewRange(elem); - if (SELECT_IE == SELECT_CURR) { + const tRange = gmGetNewRange(elem); + if (SELECT_IE === SELECT_CURR) { tRange.select(); - } else if (SELECT_G == SELECT_CURR) { - var selection = window.getSelection(); + } else if (SELECT_G === SELECT_CURR) { + selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(tRange); } @@ -1029,10 +1000,10 @@ function gmSelectText(elem, bForceSelect) { * @returns {Boolean} TRUE=the obj was deleted */ function gmDelObj(obj) { - var isDel = false; - oObj = gmGetElI(obj); + let isDel = false; + let oObj = gmGetElI(obj); if (gmIsObject(oObj)) { - var parent = oObj.parentNode; + const parent = oObj.parentNode; if (gmIsObject(parent)) { try { parent.removeChild(oObj); @@ -1052,12 +1023,12 @@ function gmDelObj(obj) { * @returns {Boolean} TRUE = always, if obj is an object, FALSE = obj is null or not an object */ function gmEmptyObj(obj) { - var isEmpty = false; - oObj = gmGetElI(obj); + let isEmpty = false; + let oObj = gmGetElI(obj); if (gmIsObject(oObj)) { while (oObj.firstChild) { oObj.removeChild(oObj.firstChild); - }; + } isEmpty = true; } return isEmpty; @@ -1069,34 +1040,103 @@ function gmEmptyObj(obj) { // --------------- // base-web.js - START // --------------- +// noinspection JSUnusedGlobalSymbols + +class PagelinksClazz { + /** + * + * @param {string} link + * @param {string|string[]} linkText + */ + constructor(link, linkText) { + this.link = link; + if (!gmIsArray(linkText)) { + this.linkText = [linkText]; + } else { + this.linkText = linkText; + } + } +} + +class KnowSiteClazz { + /** + * @param {string|RegExp} site + */ + constructor(site) { + this.site = site; + } +} + +class KnowSiteFilterClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string} filter + * @param {string|RegExp} path + */ + constructor(site, filter, path) { + super(site); + this.filter = filter; + this.path = path; + } +} + +class KnowSiteExtClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string|RegExp} url + * @param {string|RegExp} search + * @param {string|RegExp} replace + * @param {string|RegExp} replaceLarge + * @param {number} withDownload + */ + constructor(site, url, search, replace, replaceLarge, withDownload) { + super(site); + this.url = url; + this.search = search; + this.replace = replace; + this.replace_large = replaceLarge; + this.withDownload = withDownload; + } +} + +/** + * List of all URLs which are known by this script. + * @type {KnowSiteFilterClazz[]|KnowSiteExtClazz[]} + */ +let knownSite = []; /** * Minimum width of the preview. + * @type {number} */ -var minWidth = 240; +const minWidth = 240; + /** * Maximum width of the preview. + * @type {number} */ -var maxWidth = 640; +const maxWidth = 640; /** * Adds an url which should be known for the search. * - * @param filter - - * a predefined searchtext for that url - * @param site - - * the hostname as regular expression - * @param path - - * a path as regular expression (optional) + * @param {string} filter - a predefined searchtext for that url + * @param {string|RegExp} site - the hostname as regular expression + * @param {string|RegExp} path - a path as regular expression (optional) */ function gmAddSite(filter, site, path) { - if (knownSite) { - if (site && (site != "")) { - var len = knownSite.length; - knownSite[len] = new Object(); - knownSite[len].site = site; - knownSite[len].filter = (filter != null ? filter : ".+"); - knownSite[len].path = (path != null ? path : ""); + if (gmIsArray(knownSite)) { + if (site && (site.length > 0)) { + knownSite.push(new KnowSiteFilterClazz( + site, + (filter != null ? filter : ".+"), + (path != null ? path : "")) + ); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].filter = (filter != null ? filter : ".+"); + // knownSite[len].path = (path != null ? path : ""); } } } @@ -1104,31 +1144,32 @@ function gmAddSite(filter, site, path) { /** * Adds a config for a known site. * - * @param site - - * a site pattern - * @param urlElem - - * a pattern for the html-element to search in the page - * @param urlSearch - - * a pattern to search inside the url of the html-element - * @param urlReplace - - * a literal which will used for replacing the urlSearch - * @param urlReplaceLarge - - * a literal which will used for replacing the urlSearch with a url - * for large images - * @param withDownload - - * 1=will add a download-link beneath the picture, else 0 + * @param {string|RegExp} site - a site pattern + * @param {string|RegExp} urlElem - a pattern for the html-element to search in the page + * @param {string|RegExp} urlSearch - a pattern to search inside the url of the html-element + * @param {string|RegExp} urlReplace - a literal which will used for replacing the urlSearch + * @param {string|RegExp} urlReplaceLarge - a literal which will used for replacing the urlSearch with a url for large images + * @param {number} withDownload - 1=will add a download-link beneath the picture, else 0 */ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withDownload) { - if (knownSite) { + if (gmIsArray(knownSite)) { if (site && site.length > 0) { - var len = knownSite.length; - knownSite[len] = new Object(); - knownSite[len].site = site; - knownSite[len].url = (urlElem != null ? urlElem : ".+"); - knownSite[len].search = (urlSearch != null ? urlSearch : ""); - knownSite[len].replace = (urlReplace != null ? urlReplace : ""); - knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); - knownSite[len].withDownload = (withDownload != null ? withDownload : 0); + knownSite.push(new KnowSiteExtClazz( + site, + (urlElem != null ? urlElem : ".+"), + (urlSearch != null ? urlSearch : ""), + (urlReplace != null ? urlReplace : ""), + (urlReplaceLarge != null ? urlReplaceLarge : ""), + (withDownload != null ? withDownload : 0) + )); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].url = (urlElem != null ? urlElem : ".+"); + // knownSite[len].search = (urlSearch != null ? urlSearch : ""); + // knownSite[len].replace = (urlReplace != null ? urlReplace : ""); + // knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); + // knownSite[len].withDownload = (withDownload != null ? withDownload : 0); } } } @@ -1138,34 +1179,31 @@ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withD * predefined searchtext. If multiple sites will match, the LAST matching * filter will be returned. * - * @param site - - * the hostname of the site to search for - * @param path - - * the path of the site to search for (optional) - * @returns {String} the predefined searchtext + * @param {string} site - the hostname of the site to search for + * @param {string} path - the path of the site to search for (optional) + * @returns {string} the predefined searchtext */ function gmFoundFilter(site, path) { - var retFilter = ""; - var init = 0; - if (knownSite && site) { + let retFilter = ""; + if (gmIsArray(knownSite) && site) { if (!path) { path = ""; } - // alert("site: " + site + "| path: " + path); - for ( var i = 0; i < knownSite.length; i++) { - // alert("u:" + knownSite[i].site+" p:" + knownSite[i].path); - if (site.search(knownSite[i].site) >= 0) { - if (init == 0 && knownSite[i].path == "") { - retFilter = knownSite[i].filter; + //for (let i = 0; i < knownSite.length; i++) { + let init = 0; + for (let currSite of knownSite) { + //let currSite = knownSite[i]; + if (site.search(currSite.site) >= 0) { + if (init === 0 && currSite.path === "") { + retFilter = currSite.filter; init = 1; } - var fIdx = path.search(knownSite[i].path); - //alert(fIdx + " u:>" + knownSite[i].site + "< p:>" + path + "< k:>"+knownSite[i].path + "<"); - if (path != "" && (fIdx >= 0)) { - retFilter = knownSite[i].filter; + let fIdx = path.search(currSite.path); + if (path !== "" && (fIdx >= 0)) { + retFilter = currSite.filter; break; - } else if (path == "" && knownSite[i].path == "") { - retFilter = knownSite[i].filter; + } else if (path === "" && currSite.path === "") { + retFilter = currSite.filter; break; } } @@ -1175,33 +1213,42 @@ function gmFoundFilter(site, path) { } /** - * Searchs in the list of known sites, if this site is found and returns the - * predefined searchtext. If multiple sites will match, the LAST matching site - * will be returned. + * Searchs in the list of known sites, if this site is found and returns the predefined searchtext. If multiple sites will match, the LAST matching site will be returned. * - * @param site - - * the hostname of the site to search for - * @return a pattern for the html-element to search in the page + * @param {string} site - the hostname of the site to search for + * @return {KnowSiteExtClazz} a found site configuration */ function gmFoundFilter2(site) { - var retFilter = null; - if (knownSite != null && site != null) { - for (var i=0; i < knownSite.length; i++) { - if (site.search(knownSite[i].site) >= 0 ) { - retFilter = knownSite[i]; + let retFilter = null; + if (gmIsArray(knownSite) && site) { + for (let currSite of knownSite) { + if (site.search(currSite.site) >= 0) { + retFilter = currSite; } } + //for (let i = 0; i < knownSite.length; i++) { + // if (site.search(knownSite[i].site) >= 0) { + // retFilter = knownSite[i]; + //} } return retFilter; } -var FL_TAG = "result-list"; -var FL_ID = "_FL"; +/** @type {string} */ +const FL_TAG = "result-list"; +/** @type {string} */ +const FL_ID = "_FL"; +/** + * + * @param {string|HTMLElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkData(curlink, withDesc) { - var linkData = []; + const linkData = []; linkData.push(gmGetAtI(curlink, "href")); - if (withDesc != 0) { + if (withDesc !== 0) { linkData.push(gmGetAtI(curlink, "title")); linkData.push(gmGetAtI(curlink, "aria-label")); linkData.push(gmGetAtI(curlink, "alt")); @@ -1212,12 +1259,18 @@ function gmPrepareLinkData(curlink, withDesc) { return linkData; } +/** + * + * @param {string|HTMLAnchorElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkTextData(curlink, withDesc) { - var linkTextData = []; + let linkTextData = []; try { - var tmpTextData = []; + const tmpTextData = []; tmpTextData.push(curlink.text); - if (withDesc != 0) { + if (withDesc !== 0) { tmpTextData.push(gmGetAtI(curlink, "title")); tmpTextData.push(gmGetAtI(curlink, "alt")); tmpTextData.push(gmGetAtI(curlink, "aria-label")); @@ -1225,12 +1278,12 @@ function gmPrepareLinkTextData(curlink, withDesc) { tmpTextData.push(gmGetAtI(curlink, "onclick")); tmpTextData.push(curlink.innerHTML); linkTextData = tmpTextData.map(function (value) { - if (gmIsUndefined(value)) { - return ""; + if (gmIsUndefined(value)) { + return ""; } else if (gmIsObject(value)) { return value.toString(); } else if (gmIsInstanceOf(value, String)) { - return gmCleanText(value); + return gmCleanText(value); } else { return value; } @@ -1242,63 +1295,62 @@ function gmPrepareLinkTextData(curlink, withDesc) { return linkTextData; } +/** + * + * @param {string} searchPattern + * @return {RegExp} + */ function gmPrepareSearchRegExp(searchPattern) { if (!searchPattern || searchPattern.length <= 0) { searchPattern = ".*"; - } else if (searchPattern.charAt(0) == "/" && searchPattern.charAt(searchPattern.length - 1) == "/") { + } else if (searchPattern.charAt(0) === "/" && searchPattern.charAt(searchPattern.length - 1) === "/") { searchPattern = searchPattern.substring(1, searchPattern.length); - searchPattern = searchPattern.substring(0, searchPattern.length -1); + searchPattern = searchPattern.substring(0, searchPattern.length - 1); } else { searchPattern = searchPattern.replace(/\?/g, ".").replace(/\./g, "\.").replace(/\*/g, ".*"); } //alert(searchPattern); - searchPattern = new RegExp(searchPattern, "i"); - return searchPattern; + return new RegExp(searchPattern, "i"); } - /** * Search for all matching links in the page. * - * @param searchPattern - the search pattern or leave "" to get all - * @param withDesc - 0 = search only in links, + * @param {string} searchPattern - the search pattern or leave "" to get all + * @param {number} withDesc - 0 = search only in links, * 1 = search also in link description - * @returns {Array} an array with all found links + * @returns {PagelinksClazz[]} an array with all found links */ function gmFindLinksInPage(searchPattern, withDesc) { - var pagelinks = []; - if (withDesc == null) { + let pagelinks = []; + if (!withDesc) { withDesc = 0; } if (bTestMode) { pagelinks = gmGenTestEntries(40); } else { - searchPattern = gmPrepareSearchRegExp(searchPattern); - for (var i=0; i < document.links.length; i++) { - var curlink = document.links[i]; - var ne = -1; - var searchParamLink = gmPrepareLinkData(curlink, withDesc); - var found = gmLinkMatchesPattern(searchParamLink, searchPattern); - if (found) { - if (gmGetAtI(curlink.id, FL_TAG) != FL_ID) { - var htmllink = gmGetAtI(curlink, "href"); - var searchParamText = gmPrepareLinkTextData(curlink, withDesc); - var htmltext = gmLinkGenerateLinkText(searchParamText); - for (var j=0; j < pagelinks.length; j++) { - if (htmllink == pagelinks[j][0]) { - ne = j; - break; - } - } - if (ne > -1) { - pagelinks[ne][1].push(htmltext); - pagelinks[ne][1] = gmOnlyUnique(pagelinks[ne][1]); - //alert(pagelinks[ne][1]); - } else { - var curlink = [htmllink, [htmltext]]; - pagelinks.push(curlink); + //searchPattern = gmPrepareSearchRegExp(searchPattern); + //for (let linksIdx = 0; linksIdx < document.links.length; linksIdx++) { + for (let curLink of document.links) { + //let curLink = document.links[linksIdx]; + const found = gmLinkMatchesPattern(curLink, searchPattern, withDesc); + if (found && gmGetAtI(curLink.id, FL_TAG) !== FL_ID) { + let htmlLink = gmGetAtI(curLink, "href"); + let htmlText = gmLinkGenerateLinkText(curLink, withDesc); + let bFound = false; + for (let foundLinksIdx = 0; foundLinksIdx < pagelinks.length; foundLinksIdx++) { + let currPageLink = pagelinks[foundLinksIdx]; + if (htmlLink === currPageLink.link) { + bFound = true; + currPageLink.linkText.push(htmlText); + pagelinks[foundLinksIdx].linkText = gmOnlyUnique(currPageLink.linkText); + //alert(pagelinks[foundLinksIdx].linkText); + break; } } + if (!bFound) { + pagelinks.push(new PagelinksClazz(htmlLink, htmlText)); + } } } } @@ -1308,42 +1360,47 @@ function gmFindLinksInPage(searchPattern, withDesc) { /** * DON'T USE DIRECTLY * - * @param arrText - an array texts to search in - * @param searchPattern - a search text (might be a regular expression) - * @returns {Boolean} TRUE= the search text is found in the array, or FALSE - */ -function gmLinkMatchesPattern(arrText, searchPattern) { - var found = false; + * @param {string|Object} curLink + * @param {string} searchPattern - a search text (might be a regular expression) + * @param {number} withDesc + * @returns {boolean} TRUE= the search text is found in the array, or FALSE + */ +function gmLinkMatchesPattern(curLink, searchPattern, withDesc) { + let cleanSearchPattern = gmPrepareSearchRegExp(searchPattern); + const arrText = gmPrepareLinkData(curLink, withDesc); + let bFound = false; if (gmIsArray(arrText)) { - for (var i=0; i < arrText.length; i++) { - var searchText = arrText[i]; + for (let i = 0; i < arrText.length; i++) { + const searchText = arrText[i]; try { - found = searchText.search(searchPattern) != -1; + bFound = searchText.search(cleanSearchPattern) !== -1; } catch (e) { // ignored } - if (found) { + if (bFound) { break; } } } - return found; + return bFound; } /** * DON'T USE DIRECTLY * - * @param arrText - an array with the possible link descriptions - * @returns {String} the final link description - */ -function gmLinkGenerateLinkText(arrText) { - var searchTextClean = []; - var htmlText = ""; + * @param {string|Object} curLink + * @param {number} withDesc + * @returns {string} the final link description + */ +function gmLinkGenerateLinkText(curLink, withDesc) { + let arrText = gmPrepareLinkTextData(curLink, withDesc); + let searchTextClean = []; + let htmlText = ""; if (gmIsArray(arrText)) { - for (var idxST = 0; idxST < arrText.length; idxST++) { - arrText[idxST] = trim(gmCleanText(arrText[idxST])); + for (let idxST = 0; idxST < arrText.length; idxST++) { + searchTextClean[idxST] = trim(gmCleanText(arrText[idxST])); } - htmlText = gmOnlyUnique(arrText).join(""); + htmlText = gmOnlyUnique(searchTextClean).join(""); } return htmlText; } @@ -1351,20 +1408,20 @@ function gmLinkGenerateLinkText(arrText) { /** * Adds a javascript block into the page. * - * @param scc - a string, a function or an array with the javascript code or a function-list - * @returns {Boolean} TRUE = if the script block could be set, else FALSE + * @param {Object|Function|Array|string} scc - a string, a function or an array with the javascript code or a function-list + * @returns {boolean} TRUE = if the script block could be set, else FALSE */ function gmAddScriptGlobal(scc) { - var isSet = false; + let isSet = false; if (gmIsObject(scc) || gmIsFunction(scc) || (scc && scc.length > 0)) { - var head = gmGetHead(); + const head = gmGetHead(); if (head) { - var script = gmCreateObj(head, "script"); - script.type = 'text/javascript'; + const script = gmCreateObj(head, "script"); + script.type = "text/javascript"; - var allscc = ""; + let allscc = ""; if (gmIsArray(scc)) { - for ( var i = 0; i < scc.length; i++) { + for (let i = 0; i < scc.length; i++) { allscc += scc[i] + " \n"; } } else { @@ -1380,23 +1437,23 @@ function gmAddScriptGlobal(scc) { /** * Adds a link to a javascript file into the page. * - * @param scLink - a string or an array with the url of the javascript-file + * @param {string|string[]} scLink - a string or an array with the url of the javascript-file * FIXME: Check */ function gmAddScriptLinkGlobal(scLink) { - var isSet = false; - var head = gmGetHead(); + let isSet = false; + const head = gmGetHead(); if (head && scLink && scLink.length > 0) { - var allScLink = []; + let allScLink; if (gmIsArray(scLink)) { allScLink = scLink; } else { allScLink = [scLink]; } - for ( var i = 0; i < allScLink.length; i++) { - var newScript = gmCreateObj(head, "script"); - newScript.type = 'text/javascript'; + for (let i = 0; i < allScLink.length; i++) { + const newScript = gmCreateObj(head, "script"); + newScript.type = "text/javascript"; newScript.src = allScLink[i]; } isSet = true; @@ -1407,20 +1464,20 @@ function gmAddScriptLinkGlobal(scLink) { /** * Adds a style block into the page. * - * @param scc - a string or an array with the css code - * @returns {Boolean} TRUE = if the style block could be set, else FALSE + * @param {string|string[]} scc - a string or an array with the css code + * @returns {boolean} TRUE = if the style block could be set, else FALSE */ function gmAddStyleGlobal(scc) { - var isSet = false; + let isSet = false; if (gmIsObject(scc) || (scc && scc.length > 0)) { - var head = gmGetHead(); + const head = gmGetHead(); if (head) { - var style = gmCreateObj(head, "style"); - style.type = 'text/css'; + const style = gmCreateObj(head, "style"); + style.type = "text/css"; - var allscc = ""; + let allscc = ""; if (gmIsArray(scc)) { - for ( var i = 0; i < scc.length; i++) { + for (let i = 0; i < scc.length; i++) { allscc += scc[i] + " \n"; } } else { @@ -1436,11 +1493,11 @@ function gmAddStyleGlobal(scc) { /** * Generates some sample entries for testing. * - * @param maxEntries - number of entries to generate - * @returns {Array} array of entries + * @param {number} maxEntries - number of entries to generate + * @returns {PagelinksClazz[]} array of entries */ function gmGenTestEntries(maxEntries) { - if (isNaN(maxEntries) || maxEntries == "") { + if (isNaN(maxEntries)) { maxEntries = 1; } if (maxEntries < 0) { @@ -1448,13 +1505,11 @@ function gmGenTestEntries(maxEntries) { } else if (maxEntries > 100) { maxEntries = 100; } - testArray = []; - for ( var i = 1; i <= maxEntries; i++) { - var curlink = "http://" + currSite + currPath + "/link-" + i; - var htmllink = curlink; - var htmltext = "linktext-" + i; - var curlink = [htmllink, htmltext]; - testArray.push(curlink); + let testArray = []; + for (let i = 1; i <= maxEntries; i++) { + let htmlLink = "https://" + currSite + currPath + "/link-" + i; + let htmlText = "linktext-" + i; + testArray.push(new PagelinksClazz(htmlLink, htmlText)); } return testArray; } @@ -1462,13 +1517,13 @@ function gmGenTestEntries(maxEntries) { /** * Calculate the offset of an element relating to the elemnt at the most top. * - * @param element - the element to check the offeset - * @returns {Array[leftOffset, topOffset]} an array with the leftOffset, - * topOffset FIXME:TEST + * @param {Object|HTMLInputElement} element - the element to check the offeset + * @returns {number[]} an array with the leftOffset, topOffset + * FIXME:TEST */ function gmCumulativeOffset(element) { - var valueT = 0; - var valueL = 0; + let valueT = 0; + let valueL = 0; if (element) { valueL = element.width || 0; do { @@ -1477,24 +1532,22 @@ function gmCumulativeOffset(element) { element = element.offsetParent; } while (element); } - return [ valueL, valueT ]; + return [valueL, valueT]; } /** - * Calculates the horizontal offset to the right in relation to it's parent - * element. + * Calculates the horizontal offset to the right in relation to it's parent element. * - * @param parentElem - - * the element to calculate the offset from - * @param iPoint - a screen point, to add an additional offset - * @param iZoom - the zoom factor 1= Originalsize - * @returns {Number} the horizontal offset or 0 FIXME:Test + * @param {Object} parentElem - the element to calculate the offset from + * @param {Array} iPoint - a screen point, to add an additional offset + * @param {number} iZoom - the zoom factor 1= Originalsize + * @returns {number} the horizontal offset or 0 FIXME:Test */ function gmCalcOffsetH(parentElem, iPoint, iZoom) { if (isNaN(iZoom)) { iZoom = 1; } - var offsetH = 0; + let offsetH = 0; if (parentElem) { offsetH = gmCumulativeOffset(parentElem)[1]; if (!isNaN(offsetH) && gmIsArray(iPoint)) { @@ -1509,20 +1562,20 @@ function gmCalcOffsetH(parentElem, iPoint, iZoom) { /** * Searches the url for a pattern and replace the text. * - * @param searchForPattern - the pattern to search for - * @param replaceWithText - the text what will be inserted instead - * @param oldUrl - the URL to search in - * @returns {String} the url with replaced text + * @param {string} searchForPattern - the pattern to search for + * @param {string} replaceWithText - the text what will be inserted instead + * @param {string} oldUrl - the URL to search in + * @returns {string} the url with replaced text */ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { - var newUrl = oldUrl; + let newUrl = oldUrl; if (oldUrl != null) { - if (searchForPattern != "") { + if (searchForPattern !== "") { // there is something to replace if (replaceWithText == null) { replaceWithText = ""; } - var patternReplace = new RegExp(searchForPattern); + const patternReplace = new RegExp(searchForPattern); newUrl = oldUrl.replace(patternReplace, replaceWithText); } } @@ -1532,10 +1585,10 @@ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { /** * Returns the actual server of the running page. * - * @returns a server name + * @returns {string} a server name */ function gmGetCurrentSite() { - currSite = document.location.host; + let currSite = document.location.host; if (document.location.port) { currSite += ":" + document.location.port; } @@ -1545,13 +1598,12 @@ function gmGetCurrentSite() { /** * Determine the metrics of that image. * - * @param newImage - - * the image to inspect - * @returns {Array[width, height]} the image metrics [width, height] in px + * @param {Object} newImage - the image to inspect + * @returns {number[]} the image metrics [width, height] in px */ function gmGetImageSize(newImage) { - var imageObjectWidth = 0; - var imageObjectHeight = 0; + let imageObjectWidth = 0; + let imageObjectHeight = 0; if (newImage && newImage.width && newImage.width > 0) { imageObjectWidth = newImage.width; @@ -1566,31 +1618,27 @@ function gmGetImageSize(newImage) { if (imageObjectHeight <= 0) { imageObjectHeight = "auto"; } - return [ imageObjectWidth, imageObjectHeight ]; + return [imageObjectWidth, imageObjectHeight]; } /** * Add a default style to a div-element. * - * @param hDiv - - * the div-element - * @param iPoint - - * metrics of the image [width, height] in px - * @param offsetW - - * an offset (number) for the width (optional), default is 5px - * @param offsetH - - * an offset (number) for the height (optional), default is 5px - * @param ratio - - * the aspect ratio of the image, only is used, if we have no image height - * @returns {Boolean} TRUE = the layout could be added, else FALSE + * @param {Object} hDiv - the div-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} offsetW - an offset (number) for the width (optional), default is 5px + * @param {number} offsetH - an offset (number) for the height (optional), default is 5px + * @param {number} ratio - the aspect ratio of the image, only is used, if we have no image height + * @param {number} iZoom - + * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { - var w = "auto"; - var h = "auto"; - var oH = "5px"; - var oW = "5px"; + let w = "auto"; + let h = "auto"; + let oH = "5px"; + let oW = "5px"; - var isSet = false; + let isSet = false; if (gmIsObject(hDiv)) { if (isNaN(iZoom)) { iZoom = 1; @@ -1611,19 +1659,21 @@ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { if (!isNaN(offsetW)) { oW = offsetW + "px"; } + // noinspection JSCheckFunctionSignatures if (!isNaN(w)) { w *= iZoom; w = w + "px"; } + // noinspection JSCheckFunctionSignatures if (!isNaN(h)) { h *= iZoom; h = h + "px"; } - var css = gmGetAtI(hDiv, "style"); - if (css == false) { + let css = gmGetAtI(hDiv, "style"); + if (css === false) { css = ""; } - css += ";width:" + w + ";height:" + h + ";top:" + oH + ";left:" + oW ; + css += ";width:" + w + ";height:" + h + ";top:" + oH + ";left:" + oW; gmSetAtI(hDiv, "style", css); isSet = true; } @@ -1634,21 +1684,17 @@ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { /** * Add a default style to an img-element. * - * @param hDiv - - * the div-element - * @param hImg - - * the img-element - * @param iPoint - - * metrics of the image [width, height] in px - * @param iZoom - - * the zoom factor (1 = Originalsize) - * @returns {Boolean} TRUE = the layout could be added, else FALSE + * @param {Object} hDiv - the div-element + * @param {Object} hImg - the img-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} iZoom - the zoom factor (1 = Originalsize) + * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { - var h = "auto"; - var w = "auto"; + let h = "auto"; + let w = "auto"; - var isSet = false; + let isSet = false; if (gmIsObject(hDiv)) { if (isNaN(iZoom)) { iZoom = 1; @@ -1659,30 +1705,31 @@ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { } if (isNaN(iPoint[1])) { if (gmIsObject(hImg)) { - ratio = gmToNo(hImg.style.width) / gmToNo(hImg.style.height); + let ratio = gmToNo(hImg.style.width) / gmToNo(hImg.style.height); h = (gmToNo(hDiv.style.width) / ratio);// + picTextHeight; } } else { h = iPoint[1]; // + picTextHeight; } } + // noinspection JSCheckFunctionSignatures if (!isNaN(w)) { w *= iZoom; w = w + "px"; } + // noinspection JSCheckFunctionSignatures if (!isNaN(h)) { h *= iZoom; h = h + "px"; } - var css = gmGetAtI(hDiv, "style"); - if (css == false) { + let css = gmGetAtI(hDiv, "style"); + if (css === false) { css = ""; } css += ";width:" + w + ";height:" + h; gmSetAtI(hDiv, "style", css); isSet = true; } - return isSet; } @@ -1703,12 +1750,12 @@ function gmGetBody() { } /** - * @param obj - the object from which to get the css-style + * @param {string|Object} obj - the object from which to get the css-style * @returns {Object} the css-style-object from that object */ function gmGetStyle(obj) { - var res = null; - var oObj = gmGetElI(obj); + let res = null; + const oObj = gmGetElI(obj); if (oObj) { try { res = oObj.style; @@ -1720,41 +1767,50 @@ function gmGetStyle(obj) { } /** - * @returns {Integer} height of the document body + * @returns {number} height of the document body */ function gmGetBodyHeight() { - var D = gmGetBody(); - var Dh = 0; - var Eh = 0; + let D = gmGetBody(); + let Dh = 0; + let Eh = 0; if (D) { + // noinspection JSCheckFunctionSignatures Dh = Math.max(isNaN(D.style.height) ? 0 : D.style.height, D.scrollHeight, D.offsetHeight, D.clientHeight); } if (D.documentElement) { D = D.documentElement; + // noinspection JSCheckFunctionSignatures Eh = Math.max(isNaN(D.style.height) ? 0 : D.style.height, D.scrollHeight, D.offsetHeight, D.clientHeight); } return Math.max(Dh, Eh); } +/** + * + * @param {string} url + * @return {boolean} + */ function gmOpenInTab(url) { if (url) { - window.open(url,"_blank"); + window.open(url, "_blank"); } return true; } + // --------------- // base-web.js - END // --------------- // --------------- // base-clipboard.js - START // --------------- +// noinspection JSUnresolvedVariable,JSUnresolvedFunction,JSUnusedGlobalSymbols /** * @returns {Object} the reference to the base window, might be the greasemonkey * unsafeWindow */ function gmClipRef() { - var refWindow = window; + let refWindow = window; if (!refWindow && unsafeWindow != null) { refWindow = unsafeWindow; } @@ -1766,8 +1822,8 @@ function gmClipRef() { * @depricated since FF 16 */ function gmPrivsManager() { - var privsMan = null; - var wdw = gmClipRef(); + let privsMan = null; + const wdw = gmClipRef(); if (gmIsObject(wdw)) { try { if (gmIsObject(wdw.netscape.security.PrivilegeManager)) { @@ -1783,20 +1839,16 @@ function gmPrivsManager() { /** * Copies a text to clipboard. * - * @param text - - * the text to copy to the clipboard - * @param bQuite - - * don't schow any alerts - * @param refWindow - - * a reference on the page (optional) - * @returns {Boolean} text = if set to clipboard, else null + * @param {string|Object} text - the text to copy to the clipboard + * @param {boolean} bQuite - don't schow any alerts + * @param {Object} refWindow - a reference on the page (optional) + * @returns {string|null} text = if set to clipboard, else null */ function gmCopy2clipboard(text, bQuite, refWindow) { - - var resultText = text; - wdw = gmClipRef(); + const resultText = text; + let wdw = gmClipRef(); if (wdw.clipboardData) { - wdw.clipboardData.setData('text', text); + wdw.clipboardData.setData("text", text); return resultText; } else { try { @@ -1807,9 +1859,8 @@ function gmCopy2clipboard(text, bQuite, refWindow) { } return null; } - try { - e = wdw.Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(wdw.Components.interfaces.nsIClipboard); + let e = wdw.Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(wdw.Components.interfaces.nsIClipboard); if (!e) return null; } catch (ex) { @@ -1818,10 +1869,9 @@ function gmCopy2clipboard(text, bQuite, refWindow) { } return null; } - try { - b = wdw.Components.classes['@mozilla.org/widget/transferable;1'] - .createInstance(wdw.Components.interfaces.nsITransferable); + let b = wdw.Components.classes["@mozilla.org/widget/transferable;1"] + .createInstance(wdw.Components.interfaces.nsITransferable); if (!b) return null; } catch (ex) { @@ -1830,11 +1880,10 @@ function gmCopy2clipboard(text, bQuite, refWindow) { } return null; } - b.addDataFlavor("text/unicode"); try { - o = wdw.Components.classes['@mozilla.org/supports-string;1'] - .createInstance(wdw.Components.interfaces.nsISupportsString); + let o = wdw.Components.classes["@mozilla.org/supports-string;1"] + .createInstance(wdw.Components.interfaces.nsISupportsString); if (!o) return null; o.data = text; @@ -1844,39 +1893,31 @@ function gmCopy2clipboard(text, bQuite, refWindow) { } return null; } - b.setTransferData("text/unicode", o, (text == null ? 0 : text.length * 2)); - try { - t = wdw.Components.interfaces.nsIClipboard; + let t = wdw.Components.interfaces.nsIClipboard; + e.setData(b, null, t.kGlobalClipboard); } catch (ex) { if (!bQuite) { alert("4:" + ex); } return null; } - e.setData(b, null, t.kGlobalClipboard); + if (!bQuite) { + alert("Copy doesn't work!"); + } return text; } - if (!bQuite) { - alert('Copy doesn\'t work!'); - } - return null; } /** - *
- *
- * Not usable for a greasemonkey script - *
+ * Same as {@link #gmCopy2clipboard(text, bQuite, refWindow)}, but customized only for use in a webpage. + * Not usable for a greasemonkey script. * - * @param text - - * the text to copy to the clipboard + * @param {*} text - the text to copy to the clipboard */ function copyPostToClipboard(text) { - var clipboard = null, transferable = null, clipboardID = null; + let clipboard = null, transferable = null, clipboardID = null; try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { @@ -1889,21 +1930,23 @@ function copyPostToClipboard(text) { } try { transferable = Components.classes["@mozilla.org/widget/transferable;1"] - .createInstance(Components.interfaces.nsITransferable); + .createInstance(Components.interfaces.nsITransferable); } catch (e) { alert(e); } if (transferable) { transferable.addDataFlavor("text/unicode"); - var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); + const str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); str.data = text; transferable.setTransferData("text/unicode", str, str.data.length * 2); try { clipboardID = Components.interfaces.nsIClipboard; + if (clipboard) { + clipboard.setData(transferable, null, clipboardID.kGlobalClipboard); + } } catch (e) { alert(e); } - clipboard.setData(transferable, null, clipboardID.kGlobalClipboard); } } @@ -1915,12 +1958,12 @@ function gmAddClipboardSupport() { } /** - * @returns {Boolean} TRUE=using clipboard is supported, else FALSE + * @returns {boolean} TRUE=using clipboard is supported, else FALSE */ function gmIsClipboardSupported() { - var isOK = false; + let isOK = false; try { - privsMan = gmPrivsManager(); + let privsMan = gmPrivsManager(); if (gmIsObject(privsMan)) { privsMan.enablePrivilege("UniversalXPConnect"); isOK = true; @@ -1934,80 +1977,38 @@ function gmIsClipboardSupported() { // --------------- // base-clipboard.js - END // --------------- +// noinspection JSUnusedGlobalSymbols + /** * Adds site which should be known by this script. * Can be left empty. */ function lgm_addKnownSites() { - -}; +} /** * Adds CSS-Styles for this script. * Can be left empty. + * + * @return {boolean} always true */ function lgm_addStyles() { - -}; + return true; +} /** * Adds HTML-Objects for this script. * Can be left empty. */ function lgm_addControls() { - gm_addClipboardSupport(); - contlinks = gm_createObj(null, "div", "gl-container"); - odiv = gm_createObj(contlinks, "div", "gl-searchbox"); - oact = gm_createObj(contlinks, "div", "gl-actionbox"); - ores = gm_createObj(contlinks, "div", "gl-resultbox"); - oform = gm_createObj(odiv, "form", "gl-searchform"); - - initFilter = gm_foundFilter(currSite, currPath); - - gm_createInput(oform, "text", "gl-searchtext", initFilter, "enter your search (you may use regular expression)", null, null, - function() { - return gm_selectInput(this); - }); - gm_createButton(oform, "submit", "gl-sstart", "S", "start search", function() { - return lgm_filterURL('#gl-searchtext'); - }); - gm_createButton(oform, "button", "gl-sreset", "R", "clear search", function() { - return lgm_remall('#gl-searchtext'); - }); - gm_createButton(oform, "button", "gl-sshow", "\\/", "show/hide result", function() { - return lgm_showhide(); - }); - gm_createInput(oform, "text", "gl-scount", null, "number of hits", 1, null, null, null); - - var selCap = "SA"; - var selTit = "De-/Select All"; - if (gm_isClipboardSupported()) { - selCap = "CA"; - selTit = "Select & Copy All"; - } - gm_createButton(oact, "button", "gl-aselect", selCap, selTit, function() { - return lgm_selectall('gl-resultplain', 'gl-resultlink'); - }); - gm_createButton(oact, "button", "gl-ashowplain", "PR", "Show Plain Results", function() { - lgm_show('gl-resultplain', 'gl-resultlink'); - }); - gm_createButton(oact, "button", "gl-ashowlink", "RL", "Show Results as Link", function() { - lgm_show('gl-resultlink', 'gl-resultplain'); - }); - - gm_createObj(ores, "div", "gl-resultplain"); - gm_createObj(ores, "div", "gl-resultlink"); - - // document.body.appendChild(contlinks); - $("body").append(contlinks); - lgm_showhide(h_off); - -}; +} /** * The first action which should be excecuted in this script. * Can be left empty. + * + * @return {boolean} always true */ function lgm_addInitAction() { - -}; + return true; +} diff --git a/gm_base/tpl/tpl_base-core.js b/gm_base/tpl/tpl_base-core.js index 10b05b7..e22264d 100644 --- a/gm_base/tpl/tpl_base-core.js +++ b/gm_base/tpl/tpl_base-core.js @@ -3,10 +3,6 @@ // --------------- // noinspection JSUnusedGlobalSymbols -/** - * List of all URLs which are known by this script. - */ -const knownSite = []; const CURR_HOST = document.location.host; let CURR_PORT = document.location.port; diff --git a/gm_base/tpl/tpl_base-web.js b/gm_base/tpl/tpl_base-web.js index 68423eb..b6b0112 100644 --- a/gm_base/tpl/tpl_base-web.js +++ b/gm_base/tpl/tpl_base-web.js @@ -3,6 +3,69 @@ // --------------- // noinspection JSUnusedGlobalSymbols +class PagelinksClazz { + /** + * + * @param {string} link + * @param {string|string[]} linkText + */ + constructor(link, linkText) { + this.link = link; + if (!gmIsArray(linkText)) { + this.linkText = [linkText]; + } else { + this.linkText = linkText; + } + } +} + +class KnowSiteClazz { + /** + * @param {string|RegExp} site + */ + constructor(site) { + this.site = site; + } +} + +class KnowSiteFilterClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string} filter + * @param {string|RegExp} path + */ + constructor(site, filter, path) { + super(site); + this.filter = filter; + this.path = path; + } +} + +class KnowSiteExtClazz extends KnowSiteClazz { + /** + * @param {string|RegExp} site + * @param {string|RegExp} url + * @param {string|RegExp} search + * @param {string|RegExp} replace + * @param {string|RegExp} replaceLarge + * @param {number} withDownload + */ + constructor(site, url, search, replace, replaceLarge, withDownload) { + super(site); + this.url = url; + this.search = search; + this.replace = replace; + this.replace_large = replaceLarge; + this.withDownload = withDownload; + } +} + +/** + * List of all URLs which are known by this script. + * @type {KnowSiteFilterClazz[]|KnowSiteExtClazz[]} + */ +let knownSite = []; + /** * Minimum width of the preview. * @type {number} @@ -18,18 +81,23 @@ const maxWidth = 640; /** * Adds an url which should be known for the search. * - * @param filter - a predefined searchtext for that url - * @param site - the hostname as regular expression - * @param path - a path as regular expression (optional) + * @param {string} filter - a predefined searchtext for that url + * @param {string|RegExp} site - the hostname as regular expression + * @param {string|RegExp} path - a path as regular expression (optional) */ function gmAddSite(filter, site, path) { - if (knownSite) { - if (site && (site !== "")) { - const len = knownSite.length; - knownSite[len] = {}; - knownSite[len].site = site; - knownSite[len].filter = (filter != null ? filter : ".+"); - knownSite[len].path = (path != null ? path : ""); + if (gmIsArray(knownSite)) { + if (site && (site.length > 0)) { + knownSite.push(new KnowSiteFilterClazz( + site, + (filter != null ? filter : ".+"), + (path != null ? path : "")) + ); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].filter = (filter != null ? filter : ".+"); + // knownSite[len].path = (path != null ? path : ""); } } } @@ -37,24 +105,32 @@ function gmAddSite(filter, site, path) { /** * Adds a config for a known site. * - * @param site - a site pattern - * @param urlElem - a pattern for the html-element to search in the page - * @param urlSearch - a pattern to search inside the url of the html-element - * @param urlReplace - a literal which will used for replacing the urlSearch - * @param urlReplaceLarge - a literal which will used for replacing the urlSearch with a url for large images - * @param withDownload - 1=will add a download-link beneath the picture, else 0 + * @param {string|RegExp} site - a site pattern + * @param {string|RegExp} urlElem - a pattern for the html-element to search in the page + * @param {string|RegExp} urlSearch - a pattern to search inside the url of the html-element + * @param {string|RegExp} urlReplace - a literal which will used for replacing the urlSearch + * @param {string|RegExp} urlReplaceLarge - a literal which will used for replacing the urlSearch with a url for large images + * @param {number} withDownload - 1=will add a download-link beneath the picture, else 0 */ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withDownload) { - if (knownSite) { + if (gmIsArray(knownSite)) { if (site && site.length > 0) { - const len = knownSite.length; - knownSite[len] = {}; - knownSite[len].site = site; - knownSite[len].url = (urlElem != null ? urlElem : ".+"); - knownSite[len].search = (urlSearch != null ? urlSearch : ""); - knownSite[len].replace = (urlReplace != null ? urlReplace : ""); - knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); - knownSite[len].withDownload = (withDownload != null ? withDownload : 0); + knownSite.push(new KnowSiteExtClazz( + site, + (urlElem != null ? urlElem : ".+"), + (urlSearch != null ? urlSearch : ""), + (urlReplace != null ? urlReplace : ""), + (urlReplaceLarge != null ? urlReplaceLarge : ""), + (withDownload != null ? withDownload : 0) + )); + // const len = knownSite.length; + // knownSite[len] = {}; + // knownSite[len].site = site; + // knownSite[len].url = (urlElem != null ? urlElem : ".+"); + // knownSite[len].search = (urlSearch != null ? urlSearch : ""); + // knownSite[len].replace = (urlReplace != null ? urlReplace : ""); + // knownSite[len].replace_large = (urlReplaceLarge != null ? urlReplaceLarge : ""); + // knownSite[len].withDownload = (withDownload != null ? withDownload : 0); } } } @@ -64,32 +140,31 @@ function gmAddSite2(site, urlElem, urlSearch, urlReplace, urlReplaceLarge, withD * predefined searchtext. If multiple sites will match, the LAST matching * filter will be returned. * - * @param site - the hostname of the site to search for - * @param path - the path of the site to search for (optional) + * @param {string} site - the hostname of the site to search for + * @param {string} path - the path of the site to search for (optional) * @returns {string} the predefined searchtext */ function gmFoundFilter(site, path) { let retFilter = ""; - let init = 0; - if (knownSite && site) { + if (gmIsArray(knownSite) && site) { if (!path) { path = ""; } - // alert("site: " + site + "| path: " + path); - for (let i = 0; i < knownSite.length; i++) { - // alert("u:" + knownSite[i].site+" p:" + knownSite[i].path); - if (site.search(knownSite[i].site) >= 0) { - if (init === 0 && knownSite[i].path === "") { - retFilter = knownSite[i].filter; + //for (let i = 0; i < knownSite.length; i++) { + let init = 0; + for (let currSite of knownSite) { + //let currSite = knownSite[i]; + if (site.search(currSite.site) >= 0) { + if (init === 0 && currSite.path === "") { + retFilter = currSite.filter; init = 1; } - const fIdx = path.search(knownSite[i].path); - //alert(fIdx + " u:>" + knownSite[i].site + "< p:>" + path + "< k:>"+knownSite[i].path + "<"); + let fIdx = path.search(currSite.path); if (path !== "" && (fIdx >= 0)) { - retFilter = knownSite[i].filter; + retFilter = currSite.filter; break; - } else if (path === "" && knownSite[i].path === "") { - retFilter = knownSite[i].filter; + } else if (path === "" && currSite.path === "") { + retFilter = currSite.filter; break; } } @@ -101,24 +176,36 @@ function gmFoundFilter(site, path) { /** * Searchs in the list of known sites, if this site is found and returns the predefined searchtext. If multiple sites will match, the LAST matching site will be returned. * - * @param site - the hostname of the site to search for - * @return a pattern for the html-element to search in the page + * @param {string} site - the hostname of the site to search for + * @return {KnowSiteExtClazz} a found site configuration */ function gmFoundFilter2(site) { let retFilter = null; - if (knownSite != null && site != null) { - for (let i = 0; i < knownSite.length; i++) { - if (site.search(knownSite[i].site) >= 0) { - retFilter = knownSite[i]; + if (gmIsArray(knownSite) && site) { + for (let currSite of knownSite) { + if (site.search(currSite.site) >= 0) { + retFilter = currSite; } } + //for (let i = 0; i < knownSite.length; i++) { + // if (site.search(knownSite[i].site) >= 0) { + // retFilter = knownSite[i]; + //} } return retFilter; } +/** @type {string} */ const FL_TAG = "result-list"; +/** @type {string} */ const FL_ID = "_FL"; +/** + * + * @param {string|HTMLElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkData(curlink, withDesc) { const linkData = []; linkData.push(gmGetAtI(curlink, "href")); @@ -133,6 +220,12 @@ function gmPrepareLinkData(curlink, withDesc) { return linkData; } +/** + * + * @param {string|HTMLAnchorElement} curlink + * @param {number} withDesc + * @return {string[]} + */ function gmPrepareLinkTextData(curlink, withDesc) { let linkTextData = []; try { @@ -163,6 +256,11 @@ function gmPrepareLinkTextData(curlink, withDesc) { return linkTextData; } +/** + * + * @param {string} searchPattern + * @return {RegExp} + */ function gmPrepareSearchRegExp(searchPattern) { if (!searchPattern || searchPattern.length <= 0) { searchPattern = ".*"; @@ -173,52 +271,47 @@ function gmPrepareSearchRegExp(searchPattern) { searchPattern = searchPattern.replace(/\?/g, ".").replace(/\./g, "\.").replace(/\*/g, ".*"); } //alert(searchPattern); - searchPattern = new RegExp(searchPattern, "i"); - return searchPattern; + return new RegExp(searchPattern, "i"); } /** * Search for all matching links in the page. * - * @param searchPattern - the search pattern or leave "" to get all - * @param withDesc - 0 = search only in links, + * @param {string} searchPattern - the search pattern or leave "" to get all + * @param {number} withDesc - 0 = search only in links, * 1 = search also in link description - * @returns {array} an array with all found links + * @returns {PagelinksClazz[]} an array with all found links */ function gmFindLinksInPage(searchPattern, withDesc) { let pagelinks = []; - if (withDesc == null) { + if (!withDesc) { withDesc = 0; } if (bTestMode) { pagelinks = gmGenTestEntries(40); } else { - searchPattern = gmPrepareSearchRegExp(searchPattern); - for (let i = 0; i < document.links.length; i++) { - let curlink = document.links[i]; - let ne = -1; - const searchParamLink = gmPrepareLinkData(curlink, withDesc); - const found = gmLinkMatchesPattern(searchParamLink, searchPattern); - if (found) { - if (gmGetAtI(curlink.id, FL_TAG) !== FL_ID) { - const htmllink = gmGetAtI(curlink, "href"); - const searchParamText = gmPrepareLinkTextData(curlink, withDesc); - const htmltext = gmLinkGenerateLinkText(searchParamText); - for (let j = 0; j < pagelinks.length; j++) { - if (htmllink === pagelinks[j][0]) { - ne = j; - break; - } - } - if (ne > -1) { - pagelinks[ne][1].push(htmltext); - pagelinks[ne][1] = gmOnlyUnique(pagelinks[ne][1]); - //alert(pagelinks[ne][1]); - } else { - curlink = [htmllink, [htmltext]]; - pagelinks.push(curlink); + //searchPattern = gmPrepareSearchRegExp(searchPattern); + //for (let linksIdx = 0; linksIdx < document.links.length; linksIdx++) { + for (let curLink of document.links) { + //let curLink = document.links[linksIdx]; + const found = gmLinkMatchesPattern(curLink, searchPattern, withDesc); + if (found && gmGetAtI(curLink.id, FL_TAG) !== FL_ID) { + let htmlLink = gmGetAtI(curLink, "href"); + let htmlText = gmLinkGenerateLinkText(curLink, withDesc); + let bFound = false; + for (let foundLinksIdx = 0; foundLinksIdx < pagelinks.length; foundLinksIdx++) { + let currPageLink = pagelinks[foundLinksIdx]; + if (htmlLink === currPageLink.link) { + bFound = true; + currPageLink.linkText.push(htmlText); + pagelinks[foundLinksIdx].linkText = gmOnlyUnique(currPageLink.linkText); + //alert(pagelinks[foundLinksIdx].linkText); + break; } } + if (!bFound) { + pagelinks.push(new PagelinksClazz(htmlLink, htmlText)); + } } } } @@ -228,36 +321,41 @@ function gmFindLinksInPage(searchPattern, withDesc) { /** * DON'T USE DIRECTLY * - * @param arrText - an array texts to search in - * @param searchPattern - a search text (might be a regular expression) + * @param {string|Object} curLink + * @param {string} searchPattern - a search text (might be a regular expression) + * @param {number} withDesc * @returns {boolean} TRUE= the search text is found in the array, or FALSE */ -function gmLinkMatchesPattern(arrText, searchPattern) { - let found = false; +function gmLinkMatchesPattern(curLink, searchPattern, withDesc) { + let cleanSearchPattern = gmPrepareSearchRegExp(searchPattern); + const arrText = gmPrepareLinkData(curLink, withDesc); + let bFound = false; if (gmIsArray(arrText)) { for (let i = 0; i < arrText.length; i++) { const searchText = arrText[i]; try { - found = searchText.search(searchPattern) !== -1; + bFound = searchText.search(cleanSearchPattern) !== -1; } catch (e) { // ignored } - if (found) { + if (bFound) { break; } } } - return found; + return bFound; } /** * DON'T USE DIRECTLY * - * @param arrText - an array with the possible link descriptions + * @param {string|Object} curLink + * @param {number} withDesc * @returns {string} the final link description */ -function gmLinkGenerateLinkText(arrText) { - const searchTextClean = []; +function gmLinkGenerateLinkText(curLink, withDesc) { + let arrText = gmPrepareLinkTextData(curLink, withDesc); + let searchTextClean = []; let htmlText = ""; if (gmIsArray(arrText)) { for (let idxST = 0; idxST < arrText.length; idxST++) { @@ -271,7 +369,7 @@ function gmLinkGenerateLinkText(arrText) { /** * Adds a javascript block into the page. * - * @param scc - a string, a function or an array with the javascript code or a function-list + * @param {Object|Function|Array|string} scc - a string, a function or an array with the javascript code or a function-list * @returns {boolean} TRUE = if the script block could be set, else FALSE */ function gmAddScriptGlobal(scc) { @@ -300,7 +398,7 @@ function gmAddScriptGlobal(scc) { /** * Adds a link to a javascript file into the page. * - * @param scLink - a string or an array with the url of the javascript-file + * @param {string|string[]} scLink - a string or an array with the url of the javascript-file * FIXME: Check */ function gmAddScriptLinkGlobal(scLink) { @@ -327,7 +425,7 @@ function gmAddScriptLinkGlobal(scLink) { /** * Adds a style block into the page. * - * @param scc - a string or an array with the css code + * @param {string|string[]} scc - a string or an array with the css code * @returns {boolean} TRUE = if the style block could be set, else FALSE */ function gmAddStyleGlobal(scc) { @@ -356,11 +454,11 @@ function gmAddStyleGlobal(scc) { /** * Generates some sample entries for testing. * - * @param maxEntries - number of entries to generate - * @returns {Array} array of entries + * @param {number} maxEntries - number of entries to generate + * @returns {PagelinksClazz[]} array of entries */ function gmGenTestEntries(maxEntries) { - if (isNaN(maxEntries) || maxEntries === "") { + if (isNaN(maxEntries)) { maxEntries = 1; } if (maxEntries < 0) { @@ -370,10 +468,9 @@ function gmGenTestEntries(maxEntries) { } let testArray = []; for (let i = 1; i <= maxEntries; i++) { - let htmllink = "https://" + currSite + currPath + "/link-" + i; - let htmltext = "linktext-" + i; - let curlink = [htmllink, htmltext]; - testArray.push(curlink); + let htmlLink = "https://" + currSite + currPath + "/link-" + i; + let htmlText = "linktext-" + i; + testArray.push(new PagelinksClazz(htmlLink, htmlText)); } return testArray; } @@ -381,7 +478,7 @@ function gmGenTestEntries(maxEntries) { /** * Calculate the offset of an element relating to the elemnt at the most top. * - * @param {Object} element - the element to check the offeset + * @param {Object|HTMLInputElement} element - the element to check the offeset * @returns {number[]} an array with the leftOffset, topOffset * FIXME:TEST */ @@ -402,9 +499,9 @@ function gmCumulativeOffset(element) { /** * Calculates the horizontal offset to the right in relation to it's parent element. * - * @param parentElem - the element to calculate the offset from - * @param iPoint - a screen point, to add an additional offset - * @param iZoom - the zoom factor 1= Originalsize + * @param {Object} parentElem - the element to calculate the offset from + * @param {Array} iPoint - a screen point, to add an additional offset + * @param {number} iZoom - the zoom factor 1= Originalsize * @returns {number} the horizontal offset or 0 FIXME:Test */ function gmCalcOffsetH(parentElem, iPoint, iZoom) { @@ -426,9 +523,9 @@ function gmCalcOffsetH(parentElem, iPoint, iZoom) { /** * Searches the url for a pattern and replace the text. * - * @param searchForPattern - the pattern to search for - * @param replaceWithText - the text what will be inserted instead - * @param oldUrl - the URL to search in + * @param {string} searchForPattern - the pattern to search for + * @param {string} replaceWithText - the text what will be inserted instead + * @param {string} oldUrl - the URL to search in * @returns {string} the url with replaced text */ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { @@ -449,7 +546,7 @@ function gmGetReplaceUrl(searchForPattern, replaceWithText, oldUrl) { /** * Returns the actual server of the running page. * - * @returns a server name + * @returns {string} a server name */ function gmGetCurrentSite() { let currSite = document.location.host; @@ -488,12 +585,12 @@ function gmGetImageSize(newImage) { /** * Add a default style to a div-element. * - * @param hDiv - the div-element - * @param iPoint - metrics of the image [width, height] in px - * @param offsetW - an offset (number) for the width (optional), default is 5px - * @param offsetH - an offset (number) for the height (optional), default is 5px - * @param ratio - the aspect ratio of the image, only is used, if we have no image height - * @param iZoom - + * @param {Object} hDiv - the div-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} offsetW - an offset (number) for the width (optional), default is 5px + * @param {number} offsetH - an offset (number) for the height (optional), default is 5px + * @param {number} ratio - the aspect ratio of the image, only is used, if we have no image height + * @param {number} iZoom - * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { @@ -548,11 +645,11 @@ function gmSetDivLayout(hDiv, iPoint, offsetW, offsetH, ratio, iZoom) { /** * Add a default style to an img-element. * - * @param hDiv - the div-element - * @param hImg - the img-element - * @param iPoint - metrics of the image [width, height] in px - * @param iZoom - the zoom factor (1 = Originalsize) - * @returns {Boolean} TRUE = the layout could be added, else FALSE + * @param {Object} hDiv - the div-element + * @param {Object} hImg - the img-element + * @param {number[]} iPoint - metrics of the image [width, height] in px + * @param {number} iZoom - the zoom factor (1 = Originalsize) + * @returns {boolean} TRUE = the layout could be added, else FALSE */ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { let h = "auto"; @@ -594,7 +691,6 @@ function gmSetImgLayout(hDiv, hImg, iPoint, iZoom) { gmSetAtI(hDiv, "style", css); isSet = true; } - return isSet; } @@ -615,7 +711,7 @@ function gmGetBody() { } /** - * @param obj - the object from which to get the css-style + * @param {string|Object} obj - the object from which to get the css-style * @returns {Object} the css-style-object from that object */ function gmGetStyle(obj) { @@ -650,6 +746,11 @@ function gmGetBodyHeight() { return Math.max(Dh, Eh); } +/** + * + * @param {string} url + * @return {boolean} + */ function gmOpenInTab(url) { if (url) { window.open(url, "_blank"); diff --git a/grab_links/10-grab_links.iml b/grab_links/10-grab_links.iml index 8b5d532..2812fd8 100644 --- a/grab_links/10-grab_links.iml +++ b/grab_links/10-grab_links.iml @@ -9,5 +9,6 @@- *
- * Not usable for a greasemonkey script - *
+ * Same as {@link #gmCopy2clipboard(text, bQuite, refWindow)}, but customized only for use in a webpage. + * Not usable for a greasemonkey script. * - * @param text - - * the text to copy to the clipboard + * @param {*} text - the text to copy to the clipboard */ function copyPostToClipboard(text) { - var clipboard = null, transferable = null, clipboardID = null; + let clipboard = null, transferable = null, clipboardID = null; try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { @@ -1991,21 +2032,23 @@ function copyPostToClipboard(text) { } try { transferable = Components.classes["@mozilla.org/widget/transferable;1"] - .createInstance(Components.interfaces.nsITransferable); + .createInstance(Components.interfaces.nsITransferable); } catch (e) { alert(e); } if (transferable) { transferable.addDataFlavor("text/unicode"); - var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); + const str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); str.data = text; transferable.setTransferData("text/unicode", str, str.data.length * 2); try { clipboardID = Components.interfaces.nsIClipboard; + if (clipboard) { + clipboard.setData(transferable, null, clipboardID.kGlobalClipboard); + } } catch (e) { alert(e); } - clipboard.setData(transferable, null, clipboardID.kGlobalClipboard); } } @@ -2017,12 +2060,12 @@ function gmAddClipboardSupport() { } /** - * @returns {Boolean} TRUE=using clipboard is supported, else FALSE + * @returns {boolean} TRUE=using clipboard is supported, else FALSE */ function gmIsClipboardSupported() { - var isOK = false; + let isOK = false; try { - privsMan = gmPrivsManager(); + let privsMan = gmPrivsManager(); if (gmIsObject(privsMan)) { privsMan.enablePrivilege("UniversalXPConnect"); isOK = true; @@ -2036,83 +2079,41 @@ function gmIsClipboardSupported() { // --------------- // base-clipboard.js - END // --------------- +// noinspection JSUnusedGlobalSymbols + /** * Adds site which should be known by this script. * Can be left empty. */ function lgm_addKnownSites() { - -}; +} /** * Adds CSS-Styles for this script. * Can be left empty. + * + * @return {boolean} always true */ function lgm_addStyles() { - -}; + return true; +} /** * Adds HTML-Objects for this script. * Can be left empty. */ function lgm_addControls() { - gm_addClipboardSupport(); - contlinks = gm_createObj(null, "div", "gl-container"); - odiv = gm_createObj(contlinks, "div", "gl-searchbox"); - oact = gm_createObj(contlinks, "div", "gl-actionbox"); - ores = gm_createObj(contlinks, "div", "gl-resultbox"); - oform = gm_createObj(odiv, "form", "gl-searchform"); - - initFilter = gm_foundFilter(currSite, currPath); - - gm_createInput(oform, "text", "gl-searchtext", initFilter, "enter your search (you may use regular expression)", null, null, - function() { - return gm_selectInput(this); - }); - gm_createButton(oform, "submit", "gl-sstart", "S", "start search", function() { - return lgm_filterURL('#gl-searchtext'); - }); - gm_createButton(oform, "button", "gl-sreset", "R", "clear search", function() { - return lgm_remall('#gl-searchtext'); - }); - gm_createButton(oform, "button", "gl-sshow", "\\/", "show/hide result", function() { - return lgm_showhide(); - }); - gm_createInput(oform, "text", "gl-scount", null, "number of hits", 1, null, null, null); - - var selCap = "SA"; - var selTit = "De-/Select All"; - if (gm_isClipboardSupported()) { - selCap = "CA"; - selTit = "Select & Copy All"; - } - gm_createButton(oact, "button", "gl-aselect", selCap, selTit, function() { - return lgm_selectall('gl-resultplain', 'gl-resultlink'); - }); - gm_createButton(oact, "button", "gl-ashowplain", "PR", "Show Plain Results", function() { - lgm_show('gl-resultplain', 'gl-resultlink'); - }); - gm_createButton(oact, "button", "gl-ashowlink", "RL", "Show Results as Link", function() { - lgm_show('gl-resultlink', 'gl-resultplain'); - }); - - gm_createObj(ores, "div", "gl-resultplain"); - gm_createObj(ores, "div", "gl-resultlink"); - - // document.body.appendChild(contlinks); - $("body").append(contlinks); - lgm_showhide(h_off); - -}; +} /** * The first action which should be excecuted in this script. * Can be left empty. + * + * @return {boolean} always true */ function lgm_addInitAction() { - -}; + return true; +} /* This helper script bridges compatibility between the Greasemonkey 4 APIs and existing/legacy APIs. Say for example your user script includes @@ -2356,8 +2357,8 @@ function lgmAddControlsGrabLinks() { /** * Shows the layer in param frontLayer and hides the layer in param behindLayer. * - * @param {string|Object} frontLayer the layer to put in front - * @param {string|Object} behindLayer the layer to put in the bakc + * @param {string|HTMLDivElement} frontLayer the layer to put in front + * @param {string|HTMLDivElement} behindLayer the layer to put in the bakc */ function lgmSwitchResultDisplay(frontLayer, behindLayer) { const oFrontLayer = gmGetStyle(frontLayer); @@ -2389,7 +2390,7 @@ function lgmSwitchResultDisplay(frontLayer, behindLayer) { /** * Switch the search mode. * - * @param {string|Object} btnSearch - the button to read the current state from + * @param {string|HTMLButtonElement} btnSearch - the button to read the current state from */ function lgmToggleSearchDesc(btnSearch) { const oBtnSearch = gmGetElI(btnSearch); @@ -2409,11 +2410,11 @@ function lgmToggleSearchDesc(btnSearch) { /** * - * @param {string|Object} contDiv - * @param {string|Object} resultDiv - * @param {string|Object} resultPlainDiv - * @param {string|Object} resultLinkDiv - * @param {string|Object} btnAction + * @param {string|HTMLDivElement} contDiv + * @param {string|HTMLDivElement} resultDiv + * @param {string|HTMLDivElement} resultPlainDiv + * @param {string|HTMLDivElement} resultLinkDiv + * @param {string|HTMLButtonElement} btnAction */ function lgmToggleContainer(contDiv, resultDiv, resultPlainDiv, resultLinkDiv, btnAction) { const oContDiv = gmGetElI(contDiv); @@ -2484,8 +2485,6 @@ function lgmShowHideResult(bOnOff) { //alert(searchCnt); if (isNaN(searchCnt)) { currHeight = glContainerHeightMaxAuto; - //} else { - // currHeight = glContainerHeightMin; } } else { currHeight = glContainerHeightMin; @@ -2506,7 +2505,7 @@ function lgmShowHideResult(bOnOff) { /** * Clears any filter text and searchs again. * - * @param {string|Object} searchField - the search input containing the text-filter + * @param {string|HTMLInputElement} searchField - the search input containing the text-filter * @returns {boolean} always false */ function lgmResetSearch(searchField) { @@ -2522,8 +2521,8 @@ function lgmResetSearch(searchField) { /** * Selects the content of element A or B. * - * @param {string|Object} selElementA - the first container element - * @param {string|Object} selElementB - the second container element + * @param {string|HTMLElement} selElementA - the first container element + * @param {string|HTMLElement} selElementB - the second container element * @returns {boolean} always false */ function lgmSelectall(selElementA, selElementB) { @@ -2561,8 +2560,8 @@ function lgmSelectall(selElementA, selElementB) { /** * Search for all matching URLs and shows them the result. * - * @param {string|Object} searchFieldAttr - the search input containing the text-filter - * @param {string|Object} [searchModeAttr=] searchModeAttr - the searchMode input + * @param {string|HTMLInputElement} searchFieldAttr - the search input containing the text-filter + * @param {string|HTMLInputElement} [searchModeAttr=] searchModeAttr - the searchMode input * @returns {boolean} always false */ function lgmSearchLinks(searchFieldAttr, searchModeAttr) { @@ -2582,7 +2581,7 @@ function lgmSearchLinks(searchFieldAttr, searchModeAttr) { /** * Searchs for all URL in the page and optional filters by a regular expression. * - * @param {Object[]} arrLinks - array with found links + * @param {PagelinksClazz[]} arrLinks - array with found links * @returns {boolean} always false */ function lgmLinksInResult(arrLinks) { @@ -2594,13 +2593,11 @@ function lgmLinksInResult(arrLinks) { const oResultCount = gmGetElI("gl-scount"); const arrFoundInPage = gmSortArray(arrLinks); for (let i = 0; i < arrFoundInPage.length; i++) { - const currLink = arrFoundInPage[i][0]; - const currCaption = lgmCleanArrayCaption(arrFoundInPage[i][1]); + const currLink = arrFoundInPage[i].link; + const currCaption = lgmCleanArrayCaption(arrFoundInPage[i].linkText); //alert(currCaption); arrLinksPlain.push(lgmPrepareLinkAsPlain(currLink, currCaption, i)); arrLinksLink.push(lgmPrepareLinkAsLink(currLink, currCaption, i)); - // lgmPrepareLinkAsPlain(arrLinksPlain, currLink, currCaption, i); - // lgmPrepareLinkAsLink(arrLinksLink, currLink, currCaption, i); } if (oResultCount) { gmSetAtI(oResultCount, "value", arrFoundInPage.length); @@ -2665,7 +2662,7 @@ function lgmCleanArrayCaption(arrCaption) { * @param {string} currLink - the url * @param {string} currCaption - the text for the url * @param {number} curId - the id for the span - * @returns {Object} the newly span element + * @returns {HTMLSpanElement} the newly span element */ function lgmPrepareLinkAsPlain(currLink, currCaption, curId) { // row for plain text @@ -2692,7 +2689,7 @@ function lgmPrepareLinkAsPlain(currLink, currCaption, curId) { * @param {string} currLink - the url * @param {string} currCaption - the text for the url * @param {number} curId - the id for the span - * @return {Object} the newly a element + * @return {HTMLAnchorElement} the newly a element */ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { // row for htmllink @@ -2704,7 +2701,7 @@ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { return false; }, function () { - gmOpenInTab(this["href"]); + gmOpenInTab(this.href); return true; } ); @@ -2716,8 +2713,8 @@ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { /** * Fills the container element with the result object. * - * @param {string|Object} oResultLinkDiv - the container element - * @param {Object[]} arrLinksLink - array with the result objects + * @param {string|HTMLDivElement} oResultLinkDiv - the container element + * @param {HTMLAnchorElement[]} arrLinksLink - array with the result objects */ function lgmPrepareLinksInContainer(oResultLinkDiv, arrLinksLink) { gmEmptyObj(oResultLinkDiv); @@ -2730,7 +2727,7 @@ function lgmPrepareLinksInContainer(oResultLinkDiv, arrLinksLink) { /** * Select a result entry. * - * @param {Object} oEntry - a page element + * @param {HTMLElement} oEntry - a page element */ function lgmSelectEntry(oEntry) { try { diff --git a/grab_links/tpl/gl-style.user.js b/grab_links/tpl/gl-style.user.js index 63d9a81..5531e36 100644 --- a/grab_links/tpl/gl-style.user.js +++ b/grab_links/tpl/gl-style.user.js @@ -6,12 +6,13 @@ const MAIN_FORMS_CLR_BORDER = "#808080"; //"#819FF7"; const MAIN_FORMS_CLR_TEXT = MAIN_CLR_TEXT; const MAIN_FORMS_CLR_BG = "#ffffff"; const MAIN_FORMS_HEIGHT = "20px !important"; +const MAIN_FORMS_LINE_HEIGHT = "15px"; const HOVER1_CLR_TEXT = "#e0e0e0"; -const HOVER1_CLR_BG = "#A80000"; +const HOVER1_CLR_BG = "#a80000"; const HOVER2_CLR_TEXT = "#ffffff"; -const HOVER2_CLR_BG = "#A80000"; -const FOCUS_CLR_BG = "#FFFFCC"; -const SCROLLBAR_CLR_RULER = "#A00000"; //"#e0e0e0"; +const HOVER2_CLR_BG = "#a80000"; +const FOCUS_CLR_BG = "#ffffcc"; +const SCROLLBAR_CLR_RULER = "#a00000"; //"#e0e0e0"; const SCROLLBAR_CLR_BG = MAIN_FORMS_CLR_BORDER; const CSS_STYLE = ` @@ -66,10 +67,12 @@ const CSS_STYLE = ` color: ` + MAIN_FORMS_CLR_TEXT + `; background-color: ` + MAIN_FORMS_CLR_BG + `; border: 2px solid ` + MAIN_FORMS_CLR_BORDER + `; + box-sizing: border-box; font-family: ` + MAIN_FONT_TYPE + `; font-size: ` + MAIN_FONT_SIZE + `; font-weight: bold; height: ` + MAIN_FORMS_HEIGHT + `; + line-height: ` + MAIN_FORMS_LINE_HEIGHT + `; margin: 0; margin-right: 1px; max-height: ` + MAIN_FORMS_HEIGHT + `; diff --git a/grab_links/tpl/tpl_grab_links.js b/grab_links/tpl/tpl_grab_links.js index 7efda0e..b3a04e4 100644 --- a/grab_links/tpl/tpl_grab_links.js +++ b/grab_links/tpl/tpl_grab_links.js @@ -100,8 +100,8 @@ function lgmAddControlsGrabLinks() { /** * Shows the layer in param frontLayer and hides the layer in param behindLayer. * - * @param {string|Object} frontLayer the layer to put in front - * @param {string|Object} behindLayer the layer to put in the bakc + * @param {string|HTMLDivElement} frontLayer the layer to put in front + * @param {string|HTMLDivElement} behindLayer the layer to put in the bakc */ function lgmSwitchResultDisplay(frontLayer, behindLayer) { const oFrontLayer = gmGetStyle(frontLayer); @@ -133,7 +133,7 @@ function lgmSwitchResultDisplay(frontLayer, behindLayer) { /** * Switch the search mode. * - * @param {string|Object} btnSearch - the button to read the current state from + * @param {string|HTMLButtonElement} btnSearch - the button to read the current state from */ function lgmToggleSearchDesc(btnSearch) { const oBtnSearch = gmGetElI(btnSearch); @@ -153,11 +153,11 @@ function lgmToggleSearchDesc(btnSearch) { /** * - * @param {string|Object} contDiv - * @param {string|Object} resultDiv - * @param {string|Object} resultPlainDiv - * @param {string|Object} resultLinkDiv - * @param {string|Object} btnAction + * @param {string|HTMLDivElement} contDiv + * @param {string|HTMLDivElement} resultDiv + * @param {string|HTMLDivElement} resultPlainDiv + * @param {string|HTMLDivElement} resultLinkDiv + * @param {string|HTMLButtonElement} btnAction */ function lgmToggleContainer(contDiv, resultDiv, resultPlainDiv, resultLinkDiv, btnAction) { const oContDiv = gmGetElI(contDiv); @@ -228,8 +228,6 @@ function lgmShowHideResult(bOnOff) { //alert(searchCnt); if (isNaN(searchCnt)) { currHeight = glContainerHeightMaxAuto; - //} else { - // currHeight = glContainerHeightMin; } } else { currHeight = glContainerHeightMin; @@ -250,7 +248,7 @@ function lgmShowHideResult(bOnOff) { /** * Clears any filter text and searchs again. * - * @param {string|Object} searchField - the search input containing the text-filter + * @param {string|HTMLInputElement} searchField - the search input containing the text-filter * @returns {boolean} always false */ function lgmResetSearch(searchField) { @@ -266,8 +264,8 @@ function lgmResetSearch(searchField) { /** * Selects the content of element A or B. * - * @param {string|Object} selElementA - the first container element - * @param {string|Object} selElementB - the second container element + * @param {string|HTMLElement} selElementA - the first container element + * @param {string|HTMLElement} selElementB - the second container element * @returns {boolean} always false */ function lgmSelectall(selElementA, selElementB) { @@ -305,8 +303,8 @@ function lgmSelectall(selElementA, selElementB) { /** * Search for all matching URLs and shows them the result. * - * @param {string|Object} searchFieldAttr - the search input containing the text-filter - * @param {string|Object} [searchModeAttr=] searchModeAttr - the searchMode input + * @param {string|HTMLInputElement} searchFieldAttr - the search input containing the text-filter + * @param {string|HTMLInputElement} [searchModeAttr=] searchModeAttr - the searchMode input * @returns {boolean} always false */ function lgmSearchLinks(searchFieldAttr, searchModeAttr) { @@ -326,7 +324,7 @@ function lgmSearchLinks(searchFieldAttr, searchModeAttr) { /** * Searchs for all URL in the page and optional filters by a regular expression. * - * @param {Object[]} arrLinks - array with found links + * @param {PagelinksClazz[]} arrLinks - array with found links * @returns {boolean} always false */ function lgmLinksInResult(arrLinks) { @@ -338,13 +336,11 @@ function lgmLinksInResult(arrLinks) { const oResultCount = gmGetElI("gl-scount"); const arrFoundInPage = gmSortArray(arrLinks); for (let i = 0; i < arrFoundInPage.length; i++) { - const currLink = arrFoundInPage[i][0]; - const currCaption = lgmCleanArrayCaption(arrFoundInPage[i][1]); + const currLink = arrFoundInPage[i].link; + const currCaption = lgmCleanArrayCaption(arrFoundInPage[i].linkText); //alert(currCaption); arrLinksPlain.push(lgmPrepareLinkAsPlain(currLink, currCaption, i)); arrLinksLink.push(lgmPrepareLinkAsLink(currLink, currCaption, i)); - // lgmPrepareLinkAsPlain(arrLinksPlain, currLink, currCaption, i); - // lgmPrepareLinkAsLink(arrLinksLink, currLink, currCaption, i); } if (oResultCount) { gmSetAtI(oResultCount, "value", arrFoundInPage.length); @@ -409,7 +405,7 @@ function lgmCleanArrayCaption(arrCaption) { * @param {string} currLink - the url * @param {string} currCaption - the text for the url * @param {number} curId - the id for the span - * @returns {Object} the newly span element + * @returns {HTMLSpanElement} the newly span element */ function lgmPrepareLinkAsPlain(currLink, currCaption, curId) { // row for plain text @@ -436,7 +432,7 @@ function lgmPrepareLinkAsPlain(currLink, currCaption, curId) { * @param {string} currLink - the url * @param {string} currCaption - the text for the url * @param {number} curId - the id for the span - * @return {Object} the newly a element + * @return {HTMLAnchorElement} the newly a element */ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { // row for htmllink @@ -448,7 +444,7 @@ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { return false; }, function () { - gmOpenInTab(this["href"]); + gmOpenInTab(this.href); return true; } ); @@ -460,8 +456,8 @@ function lgmPrepareLinkAsLink(currLink, currCaption, curId) { /** * Fills the container element with the result object. * - * @param {string|Object} oResultLinkDiv - the container element - * @param {Object[]} arrLinksLink - array with the result objects + * @param {string|HTMLDivElement} oResultLinkDiv - the container element + * @param {HTMLAnchorElement[]} arrLinksLink - array with the result objects */ function lgmPrepareLinksInContainer(oResultLinkDiv, arrLinksLink) { gmEmptyObj(oResultLinkDiv); @@ -474,7 +470,7 @@ function lgmPrepareLinksInContainer(oResultLinkDiv, arrLinksLink) { /** * Select a result entry. * - * @param {Object} oEntry - a page element + * @param {HTMLElement} oEntry - a page element */ function lgmSelectEntry(oEntry) { try { diff --git a/xing_hover_images/tpl/tpl_footer1.js b/xing_hover_images/tpl/tpl_footer1.js index a3d2ab5..7a84860 100644 --- a/xing_hover_images/tpl/tpl_footer1.js +++ b/xing_hover_images/tpl/tpl_footer1.js @@ -3,15 +3,15 @@ * Can be left empty. */ function lgm_addKnownSites() { - gmAddSite2(".+\\.xing\.com", "\/(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); - gmAddSite2(".+\.net", "\/(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); - gmAddSite2("localhost.*", "(?:|^\/|.+?\/)(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); + gmAddSite2(".+\\.xing\.com", "\/(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0); + gmAddSite2(".+\.net", "\/(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0); + gmAddSite2("localhost.*", "(?:|^\/|.+?\/)(?:pub|)img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0); -// gmAddSite(".+\\.xing\.com", "\/img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); -// gmAddSite(".+\\.xing\.com", "\/pubimg\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); -// gmAddSite(".+\.net", "\/img\/users\/.+(?:\_s[0-9].*?|\,[0-9].[0-9]+?x[0-9]+?)\.(?:jpg|gif|png)", "(\\_s[0-9].+?|\,[0-9].[0-9]+?x[0-9]+?)\\.", ".", ".", 0 ); + // gmAddSite(".+\\.xing\.com", "\/img\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); + // gmAddSite(".+\\.xing\.com", "\/pubimg\/users\/.+(?:\_s[0-9]{1,}.*?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\.(?:jpg|gif|png)", "(\\_s[0-9]{1,}.+?|\,[0-9]{1,}.[0-9]{1,3}x[0-9]{1,3})\\.", ".", ".", 0 ); + // gmAddSite(".+\.net", "\/img\/users\/.+(?:\_s[0-9].*?|\,[0-9].[0-9]+?x[0-9]+?)\.(?:jpg|gif|png)", "(\\_s[0-9].+?|\,[0-9].[0-9]+?x[0-9]+?)\\.", ".", ".", 0 ); -}; +} /** * Adds CSS-Styles for this script. @@ -21,11 +21,11 @@ function lgm_addStyles() { GM_addStyle("a.hi-dlink, a.hi-dlink:hover {position:relative;top:2px;text-decoration:none;padding:1pt 2pt;border:#000000 solid 1px;background-color:#ffffff;color:#000000;font-size:8pt;font-weight:bold"); GM_addStyle("a.hi-dlink:hover {border:1pt #ff6080 solid;background-color:#ff6080;color:#ffffff}"); GM_addStyle("div.hi-preview {position:absolute;overflow:hidden;padding:0px;margin:0px;border:solid #cccccc 1px;" - + "z-index:1997;background-color:#eeeeee;font-family:Arial,Courier;font-size:"+picTextFontSize+";font-weight:bold;}"); + + "z-index:1997;background-color:#eeeeee;font-family:Arial,Courier;font-size:" + picTextFontSize + ";font-weight:bold;}"); GM_addStyle("img.hi-preview {border:0pt none #ffffff;z-index:1998;}"); GM_addStyle("div.hi-wait {font-size:10pt;font-weight:bold; }"); - GM_addStyle("div.hi-caption {font-size:"+picTextFontSize+";font-weight:bold;overflow:hidden;background-color:#eeeeee;z-index:1999;}"); -}; + GM_addStyle("div.hi-caption {font-size:" + picTextFontSize + ";font-weight:bold;overflow:hidden;background-color:#eeeeee;z-index:1999;}"); +} /** * Adds HTML-Objects for this script. @@ -41,10 +41,10 @@ function lgm_addControls() { elemWithDownLink = foundSite.withDownload; } -// alert(img2Search); + //alert(img2Search); - // getFilter(currSite); -}; + //getFilter(currSite); +} /** * The first action which should be excecuted in this script. @@ -52,4 +52,4 @@ function lgm_addControls() { */ function lgm_addInitAction() { lgm_initScript(null); -}; +}