Ergebnis 1 bis 13 von 13

Thema: [Grease/Tamper] Google Bilder Direktlinks

  1. #1

    [Grease/Tamper] Google Bilder Direktlinks

    Nabend,

    ich wollte mal versuchen ob man die Direktlink Funktion bei Google Bilder suche nicht über ein Greasemonkey/Tampermonkey Skript auch indirekt wiederherstellen kann.
    Und dies scheint relativ einfach möglich zu sein, zumindest für die Hauptansicht der Google Bildersuche, nicht die "relevante Untersuche" nach ähnlichen Bildern, jenes habe ich nicht eingebaut.

    Wenn mit der Maus über ein Bild gefahren wird:
    Erscheint ein "View" Link/Button, der bei Klick einen neuen Tab, direkt zum Bild öffnet (Links unten im Bild steht der Link).
    Das ganze funktioniert auch für die große Vorschau / Ansicht.

    Das funktioniert auch bei dynamisch nachgeladenen Bildern, da das kleine Skript in beliebig einstellbaren Intervallen die Seite auf Änderungen überprüft.

    Link zur aktuellen Version: https://ngb.to/threads/33425-Grease-...187#post888187



    ALT:

    Und hier das Skript, auch minimal dokumentiert.

    Edit: Alte Version, nur "normale Suche" (nicht jedoch die relevanten Bilder...) - für die relevante bitte die Version aus dem letzten Posting nehmen. Danke.

    Code (JavaScript):
    1. // ==UserScript==
    2. // @name     Google-Panic-Image
    3. // @version  1
    4. // @author   theSplit
    5. // @include  https://www.google.*
    6. // @grant    none
    7. // ==/UserScript==
    8.  
    9. // ----------------------------------------------------------------------------------------
    10. // Timings and classname for panic button
    11. // ----------------------------------------------------------------------------------------
    12.  
    13. // Seconds, when the script should scan the search page for new images
    14. let SECONDS_TO_FIRE = 4
    15.  
    16. // Our panic class (buttons)
    17. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    18.  
    19. // ----------------------------------------------------------------------------------------
    20. // Global variables
    21. // ----------------------------------------------------------------------------------------
    22. let fireAt = 0
    23. let contentHeight = 0
    24.  
    25. // ----------------------------------------------------------------------------------------
    26. // Gathers all images and adds a "view" link to the direct picture url
    27.  
    28. function rewampImgs () {
    29.   let imgLinks = document.querySelectorAll('a.rg_l')
    30.  
    31.   for (let img of imgLinks) {
    32.     let imgURL = img.href.match(/(http|https)%3A.*\.(jpg|jpeg|gif|png|webm)/g)
    33.    
    34.     if (imgURL === null) {
    35.       imgURL = img.href.match(/(http|https)%3A.*(\&imgrefurl=http)/g)
    36.      
    37.       if (imgURL !== null) imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 15)
    38.     }
    39.    
    40.     if (imgURL !== null) {
    41.       let hasControls = false
    42.      
    43.       for (let child of img.parentNode.childNodes) {
    44.         if (child.className === GOOGLE_PANIC_CLASS) {
    45.           hasControls = true
    46.           break
    47.         }
    48.       }
    49.      
    50.       if (!hasControls) {
    51.         imgURL = decodeURIComponent(imgURL[0])
    52.         img.parentNode.addEventListener('mouseenter', overlayControls)
    53.         img.parentNode.addEventListener('mouseleave', hideControls)
    54.         img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:75%;left:5%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:5px 10%;border-radius:12px;z-index:999;font-size:12px;text-decoration:none;" href="' + imgURL + '">View</a>'
    55.       }
    56.     }
    57.   }
    58. }
    59.  
    60. // ----------------------------------------------------------------------------------------
    61. // Function which does schedule the processing
    62. function waitForLoaded () {
    63.   if (Date.now() >= fireAt) {
    64.     let tmpHeight = document.querySelector('#cnt').clientHeight
    65.     if (contentHeight !== tmpHeight) {
    66.       contentHeight = tmpHeight
    67.       rewampImgs()
    68.     }
    69.    
    70.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    71.     window.requestAnimationFrame(waitForLoaded)
    72.   } else window.requestAnimationFrame(waitForLoaded)
    73. }
    74.  
    75. // ----------------------------------------------------------------------------------------
    76. // Display the controls, when the mouse is hovered over the image
    77. function overlayControls (event) {
    78.   let img = event.target
    79.   for (let child of img.childNodes) {
    80.     if (child.className === GOOGLE_PANIC_CLASS) {
    81.       child.style.visibility = 'visible'
    82.       break
    83.     }
    84.   }
    85. }
    86.  
    87. // Hide the controls, if the mouse is moved out of the image
    88. function hideControls (event) {
    89.   let img = event.target
    90.     for (let child of img.childNodes) {
    91.     if (child.className === GOOGLE_PANIC_CLASS) {
    92.       child.style.visibility = 'hidden'
    93.       break
    94.     }
    95.   }
    96. }
    97.  
    98. // ----------------------------------------------------------------------------------------
    99. // Initial run after X seconds after this script was loaded
    100. fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    101. window.requestAnimationFrame(waitForLoaded)
    102.  
    Das Script als Add-on.
    Geändert von theSplit (24.10.18 um 11:44 Uhr) Grund: Edit Hinweis neue Version
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  2. #2
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks (normale + relevante Suche)

    Okay, ich glaube jetzt passt es:

    Der "View" Link wird nun auch für die große Vorschau (bild anklicken) generiert und (scheinbar auch vorher schon) für die kleinen Thumbnails in der relevanten Suche.

    Bei den kleinen Bildern gibt es nur einen Haken: Man kann den Link (getestet in Firefox) nicht direkt anklicken, was man machen muß um die "View" Seite zu laden : Strg + Linksklick auf "View", dann geht es und es öffnet sich direkt das Bild in einem neuen Tab.

    Hier das Update:

    Code (JavaScript):
    1.  
    2.  
    3. // ==UserScript==
    4. // @name     Google-Panic-Image
    5. // @version  1
    6. // @author   theSplit
    7. // @include  https://www.google.*
    8. // @grant    none
    9. // ==/UserScript==
    10.  
    11. // ----------------------------------------------------------------------------------------
    12. // Timings and classname for panic button
    13. // ----------------------------------------------------------------------------------------
    14.  
    15. // Seconds, when the script should scan the search page for new images
    16. let SECONDS_TO_FIRE = 4
    17.  
    18. // Time after script reparsing on click on forward and next button on related images search as well as click on related images
    19. let SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.25
    20.  
    21. // Our panic class (buttons)
    22. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    23.  
    24. // ----------------------------------------------------------------------------------------
    25. // Global variables
    26. // ----------------------------------------------------------------------------------------
    27. let fireAt = 0
    28. let contentHeight = 0
    29. let currentVed = 'null'
    30.  
    31. // ----------------------------------------------------------------------------------------
    32. // Gathers all images and adds a "view" link to the direct picture url
    33.  
    34. function rewampImgs () {
    35.  
    36.   let imgLinks = document.querySelectorAll('a.rg_l')
    37.  
    38.   for (let img of imgLinks) {
    39.     if (img.childElementCount >= 2 && img.children[1].nodeName === 'SPAN') continue
    40.    
    41.     let imgURL = img.href.match(/(http|https)%3A.*\.(jpg|jpeg|gif|png|webm|JPG|JPEG|GIF|PNG|WEBM)&/g)
    42.    
    43.     if (imgURL === null) {
    44.       imgURL = img.href.match(/(http|https)%3A.*(\&imgrefurl=http)/g)
    45.      
    46.       if (imgURL !== null) imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 15)
    47.     } else {
    48.       imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 1)
    49.     }
    50.    
    51.     if (imgURL === null) {
    52.       if (img.href.indexOf('/search?q=') === -1) {
    53.         console.log('[ERROR in "rewampImgs" of google-panic-images"] The following image link could not be extracted:')
    54.         console.log(img)
    55.         console.log(img.href)
    56.       }
    57.     }
    58.  
    59.     let hasControls = false
    60.     for (let child of img.parentNode.childNodes) {
    61.       if (child.className === GOOGLE_PANIC_CLASS) {
    62.         hasControls = true
    63.         break
    64.       }
    65.     }
    66.  
    67.     if (hasControls) continue
    68.  
    69.     imgURL = decodeURIComponent(imgURL[0])
    70.     img.parentNode.addEventListener('mouseenter', overlayControls)
    71.     img.parentNode.addEventListener('mouseleave', hideControls)
    72.     img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:75%;left:5%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:5px 10%;border-radius:12px;z-index:1;font-size:12px;text-decoration:none;" href="' + imgURL + '">View</a>'
    73.   }
    74. }
    75.  
    76. // ----------------------------------------------------------------------------------------
    77. // Create / adopt the preview image link
    78.  
    79. function rewampPreviews () {
    80.   let vedSrc = document.querySelector('#irc_cb')
    81.  
    82.   if (vedSrc === null) {
    83.     console.log('[ERROR in "rewampPreviews" of google-panic-images] vedSrc not found.')
    84.     return
    85.   } else if (vedSrc.dataset === undefined) {
    86.     console.log('[ERROR in "rewampPreviews" of google-panic-images] vedSrc does not contain data-attributes.')
    87.     return
    88.   } else if (vedSrc.dataset['ved'] === undefined) {
    89.     console.log('[ERROR in "rewampPreviews" of google-panic-images] vedSrc does not contain "ved" in dataset.')
    90.     return
    91.   } else if (vedSrc.dataset['ved'].startsWith(currentVed)) {
    92.     return
    93.   }
    94.  
    95.   let previewImgs = document.querySelectorAll('img.irc_mi')
    96.   let immersiveContainers = document.querySelectorAll('div.immersive-container')
    97.    
    98.   if (previewImgs !== null && immersiveContainers !== null) {
    99.     currentVed = document.querySelector('#irc_cb').dataset['ved'].split('_')[0]    
    100.  
    101.     // Assign control click commands
    102.     let gControls = document.querySelectorAll('._KKw')
    103.     for (let control of gControls) control.addEventListener('click', resetFire)
    104.    
    105.     let imgControls = document.querySelectorAll('img.irc_rii')
    106.     for (let control of imgControls) control.addEventListener('click', resetFire)
    107.    
    108.     let previewImg = null
    109.     let imgIndex = 0
    110.    
    111.     for (let container of immersiveContainers) {
    112.       let container = immersiveContainers[imgIndex]
    113.       if (container.dataset['ved'] !== undefined && container.dataset['ved'].startsWith(currentVed)) {
    114.         previewImg = previewImgs[imgIndex]
    115.         break
    116.       }
    117.      
    118.       ++imgIndex;
    119.     }
    120.  
    121.     if (previewImg === null) {
    122.       console.log('[ERROR in "rewampPreviews" of google-panic-images] Error reading out correct preview image, skipping view link');
    123.       return
    124.     }
    125.  
    126.     let imgURLsrc = decodeURIComponent(previewImg.src)
    127.     let imgURL = imgURLsrc.match(/(http|https).*\.(jpg|jpeg|gif|png|webm|JPG|JPEG|GIF|PNG|WEBM)/g)
    128.  
    129.     if (imgURL === null) imgURL = imgURLsrc
    130.     else imgURL = imgURL[0]
    131.  
    132.     let targetContainer = document.querySelector('#irc_shc');
    133.     let hasControls = false;
    134.     for (let child of targetContainer.childNodes) {
    135.       if (child.className === GOOGLE_PANIC_CLASS) {
    136.         child.href = imgURL
    137.         hasControls = true
    138.         break
    139.       }
    140.     }
    141.  
    142.     if (!hasControls) targetContainer.innerHTML += '<a target="_blank" role="button" class="' + GOOGLE_PANIC_CLASS + '" style="cursor:pointer;visibility:visible; position:relative; top:89%;left:29%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:6px 3%;border-radius:12px;z-index:999;font-size:14px;text-decoration:none;" href="' + imgURL + '">View</a>'
    143.   }
    144. }
    145.  
    146. // ----------------------------------------------------------------------------------------
    147. // Reschedule a parsing
    148. function resetFire () {
    149.   fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
    150.   contentHeight = 0;
    151. }
    152.  
    153. // ----------------------------------------------------------------------------------------
    154. // Function which does schedule the processing
    155. function waitForLoaded () {
    156.   if (Date.now() > fireAt) {
    157.     let tmpHeight = document.querySelector('#cnt').clientHeight
    158.     if (contentHeight !== tmpHeight) {
    159.       contentHeight = tmpHeight
    160.       rewampImgs()
    161.       rewampPreviews()
    162.     }
    163.  
    164.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    165.   }
    166.  
    167.   window.requestAnimationFrame(waitForLoaded)
    168. }
    169.  
    170. // ----------------------------------------------------------------------------------------
    171. // Display the controls, when the mouse is hovered over the image
    172. function overlayControls (event) {
    173.   let img = event.target
    174.   for (let child of img.childNodes) {
    175.     if (child.className === GOOGLE_PANIC_CLASS) {
    176.       child.style.visibility = 'visible'
    177.       break
    178.     }
    179.   }
    180. }
    181.  
    182. // Hide the controls, if the mouse is moved out of the image
    183. function hideControls (event) {
    184.   let img = event.target
    185.     for (let child of img.childNodes) {
    186.     if (child.className === GOOGLE_PANIC_CLASS) {
    187.       child.style.visibility = 'hidden'
    188.       break
    189.     }
    190.   }
    191. }
    192.  
    193. // ----------------------------------------------------------------------------------------
    194. // Initial run after X seconds after this script was loaded
    195. fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    196. window.requestAnimationFrame(waitForLoaded)
    197.  
    198.  
    199.  
    Geändert von theSplit (19.02.18 um 23:18 Uhr) Grund: Einen Parsingfehler von imgURLs behoben
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  3. #3
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    So, hier nun eine weitere Version:

    - Angepasst, wenn die aktuelle Image-Ved nicht gefunden wird, wird eine alternative Methode genutzt um das aktuelle Bild zu ermitteln, welches in der Vorschau aktiv ist - dies sollte auch Probleme bei Reloads beheben
    - Styling, die "VIEW" Links in der normalen Ansicht erscheinen nun immer Links oben, da einfacher zu handhaben, nicht mittem im Bild und auch nicht die URL überlappend und haben einen hellen Rand (da auf dunklen Bildern schlecht sichtbar)
    - Styling, der "VIEW" Link für die große Bildansicht, ist nun etwas weiter unterhalb der großen Vorschaubildes platziert.
    - Angepasst, Skript Aktivierung etwas verringert

    Preview:



    Code:

    Code (JavaScript):
    1. // ==UserScript==
    2. // @name     Google-Panic-Image
    3. // @version  1
    4. // @author   theSplit
    5. // @include  https://www.google.*
    6. // @grant    none
    7. // ==/UserScript==
    8.  
    9. // ----------------------------------------------------------------------------------------
    10. // Timings and classname for panic button
    11. // ----------------------------------------------------------------------------------------
    12.  
    13. // Seconds, when the script should scan the search page for new images
    14. let SECONDS_TO_FIRE = 3
    15.  
    16. // Time after script reparsing on click on forward and next button on related images search as well as click on related images
    17. let SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.35
    18.  
    19. // Our panic class (buttons)
    20. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    21.  
    22. // ----------------------------------------------------------------------------------------
    23. // Global variables
    24. // ----------------------------------------------------------------------------------------
    25. let fireAt = 0
    26. let contentHeight = 0
    27. let currentVed = 'null'
    28. // ----------------------------------------------------------------------------------------
    29. // Gathers all images and adds a "view" link to the direct picture url
    30.  
    31. function rewampImgs () {
    32.  
    33.   let imgLinks = document.querySelectorAll('a.rg_l')
    34.  
    35.   for (let img of imgLinks) {
    36.     if (img.childElementCount >= 2 && img.children[1].nodeName === 'SPAN') continue
    37.    
    38.     let imgURL = img.href.match(/(http|https)%3A.*\.(jpg|jpeg|gif|png|webm|JPG|JPEG|GIF|PNG|WEBM)&/g)
    39.    
    40.     if (imgURL === null) {
    41.       imgURL = img.href.match(/(http|https)%3A.*(\&imgrefurl=http)/g)
    42.      
    43.       if (imgURL !== null) imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 15)
    44.     } else {
    45.       imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 1)
    46.     }
    47.    
    48.     if (imgURL === null) {
    49.       if (img.href.indexOf('/search?q=') === -1) {
    50.         console.log('[ERROR in "rewampImgs" of google-panic-images"] The following image link could not be extracted:')
    51.         console.log(img)
    52.         console.log(img.href)
    53.       }
    54.      
    55.       continue
    56.     }
    57.  
    58.     let hasControls = false
    59.     for (let child of img.parentNode.childNodes) {
    60.       if (child.className === GOOGLE_PANIC_CLASS) {
    61.         hasControls = true
    62.         break
    63.       }
    64.     }
    65.  
    66.     if (hasControls) continue
    67.  
    68.     imgURL = decodeURIComponent(imgURL[0])
    69.     img.parentNode.addEventListener('mouseenter', overlayControls)
    70.     img.parentNode.addEventListener('mouseleave', hideControls)
    71.     img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:6%;left:0%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 8% 4px 5%;border-radius:0px 12px 12px 0px;z-index:1;font-size:12px;text-decoration:none;border:1px solid #aaa;border-left: none;" href="' + imgURL + '">VIEW</a>'
    72.   }
    73. }
    74.  
    75. // ----------------------------------------------------------------------------------------
    76. // Create / adopt the preview image link
    77.  
    78. function rewampPreviews () {
    79.   let vedSrc = document.querySelector('#irc_cb')
    80.  
    81.   if (vedSrc === null) {
    82.     return
    83.   } else if (vedSrc.dataset === undefined) {
    84.     return
    85.   } else if (vedSrc.dataset['ved'] === undefined) {
    86.     return
    87.   } else if (vedSrc.dataset['ved'].startsWith(currentVed)) {
    88.     return
    89.   }
    90.  
    91.   let previewImgs = document.querySelectorAll('img.irc_mi')
    92.     let immersiveContainers = document.querySelectorAll('div.immersive-container')  
    93.    
    94.   if (previewImgs !== null && immersiveContainers !== null) {
    95.     currentVed = document.querySelector('#irc_cb').dataset['ved'].split('_')[0]
    96.  
    97.     // Assign control click commands
    98.     let gControls = document.querySelectorAll('._KKw')
    99.     for (let control of gControls) control.addEventListener('click', resetFire)
    100.    
    101.     let imgControls = document.querySelectorAll('img.irc_rii')
    102.     for (let control of imgControls) control.addEventListener('click', resetFire)
    103.    
    104.     let previewImg = null
    105.     let imgIndex = 0
    106.    
    107.     for (let container of immersiveContainers) {
    108.       let container = immersiveContainers[imgIndex]
    109.       if (container.dataset['ved'] !== undefined && container.dataset['ved'].startsWith(currentVed)) {
    110.         previewImg = previewImgs[imgIndex]
    111.         break
    112.       }
    113.      
    114.       ++imgIndex;
    115.     }
    116.  
    117.     if (previewImg === null) {
    118.       imgIndex = 0
    119.       for (let container of immersiveContainers) {
    120.         let container = immersiveContainers[imgIndex]
    121.         if (container.dataset['hveid'] !== undefined) {
    122.           previewImg = previewImgs[imgIndex]
    123.           break
    124.         }
    125.  
    126.         ++imgIndex;
    127.       }
    128.  
    129.       if (previewImg === null) {
    130.         console.log('[ERROR in "rewampPreviews" of google-panic-images] Error reading out correct large preview image link with hveid, skipping view link');
    131.         return
    132.       }
    133.     }
    134.  
    135.     let imgURLsrc = decodeURIComponent(previewImg.src)
    136.     let imgURL = imgURLsrc.match(/(http|https).*\.(jpg|jpeg|gif|png|webm|JPG|JPEG|GIF|PNG|WEBM)/g)
    137.  
    138.     if (imgURL === null) imgURL = imgURLsrc
    139.     else imgURL = imgURL[0]
    140.  
    141.     let targetContainer = document.querySelector('#irc_shc');
    142.     let hasControls = false;
    143.     for (let child of targetContainer.childNodes) {
    144.       if (child.className === GOOGLE_PANIC_CLASS) {
    145.         child.href = imgURL
    146.         hasControls = true
    147.         break
    148.       }
    149.     }
    150.  
    151.     if (!hasControls) targetContainer.innerHTML += '<a target="_blank" role="button" class="' + GOOGLE_PANIC_CLASS + '" style="cursor:pointer;visibility:visible;position:absolute;top:90%;left:30%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 10px 4px 10px;border:1px solid #aaa;border-radius:12px;z-index:999;font-size:14px;text-decoration:none;" href="' + imgURL + '">VIEW</a>'
    152.   }
    153. }
    154.  
    155. // ----------------------------------------------------------------------------------------
    156. // Reschedule a parsing
    157. function resetFire () {
    158.   fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
    159.   contentHeight = 0;
    160. }
    161.  
    162. // ----------------------------------------------------------------------------------------
    163. // Function which does schedule the processing
    164. function waitForLoaded () {
    165.  
    166.   if (Date.now() > fireAt) {
    167.     let tmpHeight = document.querySelector('#cnt').clientHeight
    168.     if (contentHeight !== tmpHeight) {
    169.       contentHeight = tmpHeight
    170.       try {
    171.         rewampImgs()
    172.       } catch (e) {
    173.         console.log('[ERROR] in script, function rewampImgs ():')
    174.         console.log(e);
    175.       }
    176.     }
    177.    
    178.     try {
    179.         rewampPreviews()
    180.       } catch (e) {
    181.         console.log('[ERROR] in script, function rewampPreviews ():')
    182.         console.log(e);
    183.       }
    184.    
    185.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    186.   }
    187.  
    188.   window.requestAnimationFrame(waitForLoaded)
    189. }
    190.  
    191. // ----------------------------------------------------------------------------------------
    192. // Display the controls, when the mouse is hovered over the image
    193. function overlayControls (event) {
    194.   let img = event.target
    195.   for (let child of img.childNodes) {
    196.     if (child.className === GOOGLE_PANIC_CLASS) {
    197.       child.style.visibility = 'visible'
    198.       break
    199.     }
    200.   }
    201. }
    202.  
    203. // Hide the controls, if the mouse is moved out of the image
    204. function hideControls (event) {
    205.   let img = event.target
    206.     for (let child of img.childNodes) {
    207.     if (child.className === GOOGLE_PANIC_CLASS) {
    208.       child.style.visibility = 'hidden'
    209.       break
    210.     }
    211.   }
    212. }
    213.  
    214. // ----------------------------------------------------------------------------------------
    215. // Initial run after X seconds after this script was loaded
    216. fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    217. window.requestAnimationFrame(waitForLoaded)
    218.  
    219.  
    Für diesen Beitrag bedankt sich LiamLie
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  4. #4
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Kurzfassung:
    + tiff und svg zu filtern hinzugefügt
    + Regex etwas optimiert (non-global (eh nur einen Treffer....), case-insensitive wegen der Schreibweisen von png, PNG, pnG usw....)
    + einige unnötige "let" entfernt.

    Im Falle von Fehlern oder Wünschen melden.

    Nachtrag: Ich hab noch keine gute Methode gefunden zu erkennen, wenn sich etwas nachgeladen hat, zum Beispiel weil Google neue Bilder beim scrollen nachlädt, über Tips wäre ich sehr dankbar.

    Code (JavaScript):
    1. // ==UserScript==
    2. // @name     Google-Panic-Image
    3. // @version  1.1
    4. // @author   theSplit <touch@dwrox.net>
    5. // @include  https://www.google.*
    6. // @grant    none
    7. // ==/UserScript==
    8.  
    9. // ----------------------------------------------------------------------------------------
    10. // Timings and classname for panic button
    11. // ----------------------------------------------------------------------------------------
    12.  
    13. // Seconds, when the script should scan the search page for new images
    14. let SECONDS_TO_FIRE = 3
    15.  
    16. // Time after script reparsing on click on forward and next button on related images search as well as click on related images
    17. let SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.35
    18.  
    19. // Our panic class (buttons)
    20. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    21.  
    22. // ----------------------------------------------------------------------------------------
    23. // Global variables
    24. // ----------------------------------------------------------------------------------------
    25. let fireAt = 0
    26. let contentHeight = 0
    27. let currentVed = 'null'
    28. // ----------------------------------------------------------------------------------------
    29. // Gathers all images and adds a "view" link to the direct picture url
    30.  
    31. function rewampImgs () {
    32.  
    33.   let imgLinks = document.querySelectorAll('a.rg_l')
    34.  
    35.   for (let img of imgLinks) {
    36.     if (img.childElementCount >= 2 && img.children[1].nodeName === 'SPAN') continue
    37.    
    38.     let imgURL = img.href.match(/(http|https)%3A.*\.(jpg|jpeg|gif|png|webm|svg|tiff)&/i)
    39.    
    40.     if (imgURL === null) {
    41.       imgURL = img.href.match(/(http|https)%3A.*(\&imgrefurl=http)/i)
    42.      
    43.       if (imgURL !== null) imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 15)
    44.     } else {
    45.       imgURL[0] = imgURL[0].substr(0, imgURL[0].length - 1)
    46.     }
    47.    
    48.     if (imgURL === null) {
    49.       if (img.href.indexOf('/search?q=') === -1) {
    50.         console.log('[ERROR in "rewampImgs" of google-panic-images"] The following image link could not be extracted:')
    51.         console.log(img)
    52.         console.log(img.href)
    53.       }
    54.      
    55.       continue
    56.     }
    57.  
    58.     let hasControls = false
    59.     for (let child of img.parentNode.childNodes) {
    60.       if (child.className === GOOGLE_PANIC_CLASS) {
    61.         hasControls = true
    62.         break
    63.       }
    64.     }
    65.  
    66.     if (hasControls) continue
    67.  
    68.     imgURL = decodeURIComponent(imgURL[0])
    69.     img.parentNode.addEventListener('mouseenter', overlayControls)
    70.     img.parentNode.addEventListener('mouseleave', hideControls)
    71.     img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:6%;left:0%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 8% 4px 5%;border-radius:0px 12px 12px 0px;z-index:1;font-size:12px;text-decoration:none;border:1px solid #aaa;border-left: none;" href="' + imgURL + '">VIEW</a>'
    72.   }
    73. }
    74.  
    75. // ----------------------------------------------------------------------------------------
    76. // Create / adopt the preview image link
    77.  
    78. function rewampPreviews () {
    79.   let vedSrc = document.querySelector('#irc_cb')
    80.  
    81.   if (vedSrc === null) {
    82.     return
    83.   } else if (vedSrc.dataset === undefined) {
    84.     return
    85.   } else if (vedSrc.dataset['ved'] === undefined) {
    86.     return
    87.   } else if (vedSrc.dataset['ved'].startsWith(currentVed)) {
    88.     return
    89.   }
    90.  
    91.   let previewImgs = document.querySelectorAll('img.irc_mi')
    92.     let immersiveContainers = document.querySelectorAll('div.immersive-container')  
    93.    
    94.   if (previewImgs !== null && immersiveContainers !== null) {
    95.     currentVed = document.querySelector('#irc_cb').dataset['ved'].split('_', 1)[0]
    96.  
    97.     // Assign control click commands
    98.     let gControls = document.querySelectorAll('._KKw')
    99.     for (let control of gControls) control.addEventListener('click', resetFire)
    100.    
    101.     let imgControls = document.querySelectorAll('img.irc_rii')
    102.     for (let control of imgControls) control.addEventListener('click', resetFire)
    103.    
    104.     let previewImg = null
    105.     let imgIndex = 0
    106.    
    107.     for (let container of immersiveContainers) {
    108.       if (container.dataset['ved'] !== undefined && container.dataset['ved'].startsWith(currentVed)) {
    109.         previewImg = previewImgs[imgIndex]
    110.         break
    111.       }
    112.      
    113.       ++imgIndex;
    114.     }
    115.  
    116.     if (previewImg === null) {
    117.       imgIndex = 0
    118.       for (let container of immersiveContainers) {
    119.         if (container.dataset['hveid'] !== undefined) {
    120.           previewImg = previewImgs[imgIndex]
    121.           break
    122.         }
    123.  
    124.         ++imgIndex;
    125.       }
    126.  
    127.       if (previewImg === null) {
    128.         console.log('[ERROR in "rewampPreviews" of google-panic-images] Error reading out correct large preview image link with hveid, skipping view link');
    129.         return
    130.       }
    131.     }
    132.  
    133.     let imgURLsrc = decodeURIComponent(previewImg.src)
    134.     let imgURL = imgURLsrc.match(/(http|https).*\.(jpg|jpeg|gif|png|webm|svg|tiff)/i)
    135.  
    136.     if (imgURL === null) imgURL = imgURLsrc
    137.     else imgURL = imgURL[0]
    138.  
    139.     let targetContainer = document.querySelector('#irc_shc');
    140.     let hasControls = false;
    141.     for (let child of targetContainer.childNodes) {
    142.       if (child.className === GOOGLE_PANIC_CLASS) {
    143.         child.href = imgURL
    144.         hasControls = true
    145.         break
    146.       }
    147.     }
    148.  
    149.     if (!hasControls) targetContainer.innerHTML += '<a target="_blank" role="button" class="' + GOOGLE_PANIC_CLASS + '" style="cursor:pointer;visibility:visible;position:absolute;top:90%;left:30%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 10px 4px 10px;border:1px solid #aaa;border-radius:12px;z-index:999;font-size:14px;text-decoration:none;" href="' + imgURL + '">VIEW</a>'
    150.   }
    151. }
    152.  
    153. // ----------------------------------------------------------------------------------------
    154. // Reschedule a parsing
    155. function resetFire () {
    156.   fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
    157.   contentHeight = 0;
    158. }
    159.  
    160. // ----------------------------------------------------------------------------------------
    161. // Function which does schedule the processing
    162. function waitForLoaded () {
    163.  
    164.   if (Date.now() > fireAt) {
    165.     let tmpHeight = document.querySelector('#cnt').clientHeight
    166.     if (contentHeight !== tmpHeight) {
    167.       contentHeight = tmpHeight
    168.       try {
    169.         rewampImgs()
    170.       } catch (e) {
    171.         console.log('[ERROR] in script, function rewampImgs ():')
    172.         console.log(e);
    173.       }
    174.     }
    175.    
    176.     try {
    177.       rewampPreviews()
    178.     } catch (e) {
    179.       console.log('[ERROR] in script, function rewampPreviews ():')
    180.       console.log(e);
    181.     }
    182.    
    183.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    184.   }
    185.  
    186.   window.requestAnimationFrame(waitForLoaded)
    187. }
    188.  
    189.  
    190. // ----------------------------------------------------------------------------------------
    191. // Display the controls, when the mouse is hovered over the image
    192. function overlayControls (event) {
    193.   let img = event.target
    194.   for (let child of img.childNodes) {
    195.     if (child.className === GOOGLE_PANIC_CLASS) {
    196.       child.style.visibility = 'visible'
    197.       break
    198.     }
    199.   }
    200. }
    201.  
    202. // Hide the controls, if the mouse is moved out of the image
    203. function hideControls (event) {
    204.   let img = event.target
    205.     for (let child of img.childNodes) {
    206.     if (child.className === GOOGLE_PANIC_CLASS) {
    207.       child.style.visibility = 'hidden'
    208.       break
    209.     }
    210.   }
    211. }
    212.  
    213. // ----------------------------------------------------------------------------------------
    214. document.onreadystatechange = waitForLoaded()
    215.  
    Für diesen Beitrag bedankt sich Mäxchen
    Geändert von theSplit (18.07.18 um 08:50 Uhr)
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  5. #5
    lustiger Kumpane Avatar von Mäxchen
    Registriert seit
    Jul 2013
    Ort
    am liebsten im Zelt
    Beiträge
    43

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Das ist ein tolles script. Dass ich nicht schon früher auf dieses Thema gestoßen bin...danke dir.
    Habe zum testen mal nach "girl" gegoogelt. Ein Beispiellink ist "https://images.pexels.com/photos/255349/pexels-photo-255349.jpeg?cs=srgb&dl=person-woman-field-255349.jpg&fm=jpg". Bei dem Link versucht der Browser, das Foto sofort runterzuladen, und nicht in einem neuen Tab zu öffnen. Vielleicht könnte man alles ab dem "?" entfernen? Ansonsten scheint alles perfekt zu funktionieren.
    Für diesen Beitrag bedankt sich theSplit
    33,33% aller Statistiken beruhen auf sehr kleinen Datenmengen.

  6. #6
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    @Mäxchen: Danke für das Lob, das kommt gut!

    Ich bin deinem Link auf die Spur gegangen und habe den Fehler behoben.
    Dank deines Einwands versucht das Skript nun noch beharrlicher die Bilddatei zu finden. [In imgurl + imgrefurl und fällt ansonsten zurück auf die imgurl]
    Alles in allem eine gute Verbesserung.

    Hier ist die modifizierte Version:

    Code (JavaScript):
    1. // ==UserScript==
    2. // @name     Google-Panic-Image
    3. // @version  1.1.1
    4. // @author   theSplit <touch@dwrox.net>
    5. // @include  https://www.google.*
    6. // @grant    none
    7. // ==/UserScript==
    8.  
    9. // ----------------------------------------------------------------------------------------
    10. // Timings and classname for panic button
    11. // ----------------------------------------------------------------------------------------
    12.  
    13. // Seconds, when the script should scan the search page for new images
    14. let SECONDS_TO_FIRE = 3
    15.  
    16. // Time after script reparsing on click on forward and next button on related images search as well as click on related images
    17. let SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.35
    18.  
    19. // Our panic class (buttons)
    20. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    21.  
    22. // ----------------------------------------------------------------------------------------
    23. // Global variables
    24. // ----------------------------------------------------------------------------------------
    25. let fireAt = 0
    26. let contentHeight = 0
    27. let currentVed = 'null'
    28. // ----------------------------------------------------------------------------------------
    29.  
    30. // RegExParsers
    31. let imgRegExBase = /imgurl=(http[s]{0,1}%3A.*?(jpg|jpeg|gif|png|webm|svg|tiff))/i
    32. let imgRegExRef = /imgurlref=(http[s]{0,1}%3A.*?(jpg|jpeg|gif|png|webm|svg|tiff))/i
    33. let imgRegExBaseNoImage = /imgurl=(http[s]{0,1}%3A.[^&?]*)/i
    34.  
    35. // Gathers all images and adds a "view" link to the direct picture url
    36. function rewampImgs () {
    37.  
    38.   let imgLinks = document.querySelectorAll('a.rg_l')
    39.  
    40.   for (let img of imgLinks) {
    41.     if (img.childElementCount >= 2 && img.children[1].nodeName === 'SPAN') continue
    42.    
    43.     let imgURL = imgRegExBase.exec(img.href)
    44.    
    45.     if (imgURL === null) {
    46.       imgURL = imgRegExRef.exec(img.href)
    47.      
    48.       if (imgURL === null) {
    49.         imgURL = imgRegExBaseNoImage.exec(img.href)
    50.        
    51.         if (imgURL === null) {
    52.           if (img.href.indexOf('imgurl=') !== -1) {
    53.             img.style.border = '6px solid #000'
    54.             console.log('[ERROR in "rewampImgs" of google-panic-images"] The following image link could not be extracted:')
    55.             console.log(img)
    56.             console.log(img.href)
    57.           }
    58.  
    59.           continue
    60.         }
    61.       }
    62.     }
    63.    
    64.     imgURL = imgURL[1]
    65.    
    66.     let hasControls = false
    67.     for (let child of img.parentNode.childNodes) {
    68.       if (child.className === GOOGLE_PANIC_CLASS) {
    69.         hasControls = true
    70.         break
    71.       }
    72.     }
    73.  
    74.     if (hasControls) continue
    75.  
    76.     imgURL = decodeURIComponent(imgURL)
    77.     img.parentNode.addEventListener('mouseenter', overlayControls)
    78.     img.parentNode.addEventListener('mouseleave', hideControls)
    79.     img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:6%;left:0%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 8% 4px 5%;border-radius:0px 12px 12px 0px;z-index:1;font-size:12px;text-decoration:none;border:1px solid #aaa;border-left: none;" href="' + imgURL + '">VIEW</a>'
    80.   }
    81. }
    82.  
    83. // ----------------------------------------------------------------------------------------
    84. // Create / adopt the preview image link
    85.  
    86. function rewampPreviews () {
    87.   let vedSrc = document.querySelector('#irc_cb')
    88.  
    89.   if (vedSrc === null) {
    90.     return
    91.   } else if (vedSrc.dataset === undefined) {
    92.     return
    93.   } else if (vedSrc.dataset['ved'] === undefined) {
    94.     return
    95.   } else if (vedSrc.dataset['ved'].startsWith(currentVed)) {
    96.     return
    97.   }
    98.  
    99.   let previewImgs = document.querySelectorAll('img.irc_mi')
    100.     let immersiveContainers = document.querySelectorAll('div.immersive-container')  
    101.    
    102.   if (previewImgs !== null && immersiveContainers !== null) {
    103.     currentVed = document.querySelector('#irc_cb').dataset['ved'].split('_', 1)[0]
    104.  
    105.     // Assign control click commands
    106.     let gControls = document.querySelectorAll('._KKw')
    107.     for (let control of gControls) control.addEventListener('click', resetFire)
    108.    
    109.     let imgControls = document.querySelectorAll('img.irc_rii')
    110.     for (let control of imgControls) control.addEventListener('click', resetFire)
    111.    
    112.     let previewImg = null
    113.     let imgIndex = 0
    114.    
    115.     for (let container of immersiveContainers) {
    116.       if (container.dataset['ved'] !== undefined && container.dataset['ved'].startsWith(currentVed)) {
    117.         previewImg = previewImgs[imgIndex]
    118.         break
    119.       }
    120.      
    121.       ++imgIndex;
    122.     }
    123.  
    124.     if (previewImg === null) {
    125.       imgIndex = 0
    126.       for (let container of immersiveContainers) {
    127.         if (container.dataset['hveid'] !== undefined) {
    128.           previewImg = previewImgs[imgIndex]
    129.           break
    130.         }
    131.  
    132.         ++imgIndex;
    133.       }
    134.  
    135.       if (previewImg === null) {
    136.         console.log('[ERROR in "rewampPreviews" of google-panic-images] Error reading out correct large preview image link with hveid, skipping view link');
    137.         return
    138.       }
    139.     }
    140.  
    141.     let imgURLsrc = decodeURIComponent(previewImg.src)
    142.     let imgURL = imgRegExBase.exec(imgURLsrc)
    143.    
    144.     if (imgURL === null) {
    145.             imgURL = imgRegExRef.exec(imgURLsrc)
    146.      
    147.       if (imgURL === null) imgURL = imgRegExBaseNoImage.exec(imgURLsrc)
    148.     }
    149.    
    150.     if (imgURL === null) imgURL = imgURLsrc
    151.     else imgURL = imgURL[1]
    152.    
    153.     let targetContainer = document.querySelector('#irc_shc');
    154.     let hasControls = false;
    155.     for (let child of targetContainer.childNodes) {
    156.       if (child.className === GOOGLE_PANIC_CLASS) {
    157.         child.href = imgURL
    158.         hasControls = true
    159.         break
    160.       }
    161.     }
    162.  
    163.     if (!hasControls) targetContainer.innerHTML += '<a target="_blank" role="button" class="' + GOOGLE_PANIC_CLASS + '" style="cursor:pointer;visibility:visible;position:absolute;top:90%;left:30%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 10px 4px 10px;border:1px solid #aaa;border-radius:12px;z-index:999;font-size:14px;text-decoration:none;" href="' + imgURL + '">VIEW</a>'
    164.   }
    165. }
    166.  
    167. // ----------------------------------------------------------------------------------------
    168. // Reschedule a parsing
    169. function resetFire () {
    170.   fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
    171.   contentHeight = 0;
    172. }
    173.  
    174. // ----------------------------------------------------------------------------------------
    175. // Function which does schedule the processing
    176. function waitForLoaded () {
    177.  
    178.   if (Date.now() > fireAt) {
    179.     let tmpHeight = document.querySelector('#cnt').clientHeight
    180.     if (contentHeight !== tmpHeight) {
    181.       contentHeight = tmpHeight
    182.       try {
    183.         rewampImgs()
    184.       } catch (e) {
    185.         console.log('[ERROR] in script, function rewampImgs ():')
    186.         console.log(e);
    187.       }
    188.     }
    189.    
    190.     try {
    191.       rewampPreviews()
    192.     } catch (e) {
    193.       console.log('[ERROR] in script, function rewampPreviews ():')
    194.       console.log(e);
    195.     }
    196.    
    197.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    198.   }
    199.  
    200.   window.requestAnimationFrame(waitForLoaded)
    201. }
    202.  
    203.  
    204. // ----------------------------------------------------------------------------------------
    205. // Display the controls, when the mouse is hovered over the image
    206. function overlayControls (event) {
    207.   let img = event.target
    208.   for (let child of img.childNodes) {
    209.     if (child.className === GOOGLE_PANIC_CLASS) {
    210.       child.style.visibility = 'visible'
    211.       break
    212.     }
    213.   }
    214. }
    215.  
    216. // Hide the controls, if the mouse is moved out of the image
    217. function hideControls (event) {
    218.   let img = event.target
    219.     for (let child of img.childNodes) {
    220.     if (child.className === GOOGLE_PANIC_CLASS) {
    221.       child.style.visibility = 'hidden'
    222.       break
    223.     }
    224.   }
    225. }
    226.  
    227. // ----------------------------------------------------------------------------------------
    228. document.onreadystatechange = waitForLoaded()
    Für diesen Beitrag bedankt sich Mäxchen
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  7. #7
    lustiger Kumpane Avatar von Mäxchen
    Registriert seit
    Jul 2013
    Ort
    am liebsten im Zelt
    Beiträge
    43

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Es funktioniert auf jeden Fall praktischer als Google es früher selbst gemacht hat. Hier sind noch ein paar Testlinks, die nicht funktionieren. Man muss aber schon richtig suchen, um welche zu finden, die nicht klappen, und richtig schmlimm ist es auch nicht, wenn vereinzelte nicht gehen.
    "https://www.bgland24.de/bilder/2017/06/26/8431951/2018164693-24-girl-jacqueline-1bjpG"
    "https://lookaside.fbsbx.com/lookaside/crawler/media/?media_id=999104790102064"
    "https://r.hswstatic.com/w_907/gif"
    Für diesen Beitrag bedankt sich theSplit
    Geändert von Mäxchen (18.07.18 um 22:14 Uhr)
    33,33% aller Statistiken beruhen auf sehr kleinen Datenmengen.

  8. #8
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Schön zu hören das es praktischer ist. So muß das sein!

    "https://www.bgland24.de/bilder/2017/06/26/8431951/2018164693-24-girl-jacqueline-1bjpG"
    "https://lookaside.fbsbx.com/lookaside/crawler/media/?media_id=999104790102064"
    Ich glaube hier wird es schwer:

    Zu diesen beiden Links, hast du da den Original Google Link irgendwie greifbar? (mit modifizierent Werten, "ved", "ei", "psy_l" oder was auch immer da nicht in:
    google.de/search?q=SUCHANFRAGE&imgurl=http%3A.......................&imgrefurl=http12345

    Interessant sind die imgurl und die imgrefurl - da beziehe ich aktuell auch die Informationen her.

    Allerdings stehen in deinem ersten Link kein Dateiformat und die URL scheint broken zu sein. Ich erreiche darüber jetzt keine Inhalte wenn ich sie aufrufe.

    Zum zweiten Link da müsste ich genauer schauen, ob ich irgendwie eine Info bekommen kann, außerhalb dessen was "in der Übersicht" angezeigt wird.
    Aber im Grunde ist das ein zensierter Facebook Link, so wie ich es sehe, daher die Ausweisung für in Crawler/Media" mit ID=12345.

    Ein Schwierigkeit dabei ist nur, es gibt Quellurls ohne Datentyp (zu beiden Links) - also greife ich darauf zurück was ich nicht identifizieren kann, aber "gültig sein könnte" -
    Zum Beispiel der hier:
    https://www.google.de/imgres?imgurl=...&w=1024&h=1024

    ist eigentlich der hier, wenn du klickst:
    https://s3.amazonaws.com/tinycards/i...ae39d1221e5ca8

    ...beide URLs haben keine Dateiendung, sind aber gültig und verweisen auf Bildcontent.
    Geändert von theSplit (18.07.18 um 22:40 Uhr)
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  9. #9
    lustiger Kumpane Avatar von Mäxchen
    Registriert seit
    Jul 2013
    Ort
    am liebsten im Zelt
    Beiträge
    43

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Das hier ist der erste Link. Hoffe, das hilft. Der Link, den dein Skript ausgibt, endet auf "jpG" Diese Buchstabenkombination scheint aber nur zufällig innerhalb des Dateinamen zu sein.
    "https://www.google.de/imgres?imgurl=https%3A%2F%2Fwww.bgland24.de%2Fbilder%2F2017%2F06%2F26%2F8431951%2F2018164693-24-girl-jacqueline-1bjpGT9bf.jpg&imgrefurl=https%3A%2F%2Fwww.bgland24.de%2Fleben%2F24-girl%2Fstefan-schmid%2F&docid=elyGz4L62e6mhM&tbnid=N2ifibtkrFm-3M%3A&vet=10ahUKEwi5-umuxqncAhUrsqQKHRSUBfAQMwh8KD4wPg..i&w=256&h=192&bih=601&biw=1280&q=girl&ved=0ahUKEwi5-umuxqncAhUrsqQKHRSUBfAQMwh8KD4wPg&iact=mrc&uact=8"

    Das hier zum zweiten:
    "https://www.google.de/imgres?imgurl=https%3A%2F%2Flookaside.fbsbx.com%2Flookaside%2Fcrawler%2Fmedia%2F%3Fmedia_id%3D999104790102064&imgrefurl=https%3A%2F%2Fde-de.facebook.com%2FOfficialCommonGirl%2F&docid=aH4Uy9Be2mh3gM&tbnid=zQfoNKxj3XdVJM%3A&vet=10ahUKEwi5-umuxqncAhUrsqQKHRSUBfAQMwg9KAowCg..i&w=585&h=585&bih=601&biw=1280&q=girl&ved=0ahUKEwi5-umuxqncAhUrsqQKHRSUBfAQMwg9KAowCg&iact=mrc&uact=8"
    Für diesen Beitrag bedankt sich theSplit
    33,33% aller Statistiken beruhen auf sehr kleinen Datenmengen.

  10. #10
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Der zweite Link verweist entweder auf das Userprofil, oder den Medialink mit Facebook Seite:
    https://de-de.facebook.com/OfficialCommonGirl/
    https://lookaside.fbsbx.com/lookasid...99104790102064

    Da ist also nicht direkt beizukommen aus der Übersicht.

    Zum ersten kann ich eine positive Rückmeldung geben, das geht mit folgendem: [liegt am am Regex und Case-insensitivity, weil "jpg" auf "jpG" trifft und nen Treffer liefert]

    Hier der Code, geändert haben sich die "RegExParsers" bei Zeile 29 bis 33

    Code (JavaScript):
    1. // RegExParsers
    2. let imgRegExBase = /imgurl=(http[s]{0,1}%3A.*?\.(jpg|jpeg|gif|png|webm|svg|tiff))/i
    3. let imgRegExRef = /imgurlref=(http[s]{0,1}%3A.*?\.(jpg|jpeg|gif|png|webm|svg|tiff))/i
    4. let imgRegExBaseNoImage = /imgurl=(http[s]{0,1}%3A.[^&?]*)/i
    Hier gesamter Code:

    Spoiler: 

    Code (JavaScript):
    1. // ==UserScript==
    2. // @name     Google-Panic-Image
    3. // @version  1.1.2
    4. // @author   theSplit <touch@dwrox.net>
    5. // @include  https://www.google.*
    6. // @grant    none
    7. // ==/UserScript==
    8.  
    9. // ----------------------------------------------------------------------------------------
    10. // Timings and classname for panic button
    11. // ----------------------------------------------------------------------------------------
    12.  
    13. // Seconds, when the script should scan the search page for new images
    14. let SECONDS_TO_FIRE = 3
    15.  
    16. // Time after script reparsing on click on forward and next button on related images search as well as click on related images
    17. let SECONDS_TO_FIRE_CUT = SECONDS_TO_FIRE * 0.35
    18.  
    19. // Our panic class (buttons)
    20. let GOOGLE_PANIC_CLASS = 'Google-panic-image-btn'
    21.  
    22. // ----------------------------------------------------------------------------------------
    23. // Global variables
    24. // ----------------------------------------------------------------------------------------
    25. let fireAt = 0
    26. let contentHeight = 0
    27. let currentVed = 'null'
    28. // ----------------------------------------------------------------------------------------
    29.  
    30. // RegExParsers
    31. let imgRegExBase = /imgurl=(http[s]{0,1}%3A.*?\.(jpg|jpeg|gif|png|webm|svg|tiff))/i
    32. let imgRegExRef = /imgurlref=(http[s]{0,1}%3A.*?\.(jpg|jpeg|gif|png|webm|svg|tiff))/i
    33. let imgRegExBaseNoImage = /imgurl=(http[s]{0,1}%3A.[^&?]*)/i
    34.  
    35. // Gathers all images and adds a "view" link to the direct picture url
    36. function rewampImgs () {
    37.  
    38.   let imgLinks = document.querySelectorAll('a.rg_l')
    39.  
    40.   for (let img of imgLinks) {
    41.     if (img.childElementCount >= 2 && img.children[1].nodeName === 'SPAN') continue
    42.    
    43.     let imgURL = imgRegExBase.exec(img.href)
    44.    
    45.     if (imgURL === null) {
    46.       imgURL = imgRegExRef.exec(img.href)
    47.      
    48.       if (imgURL === null) {
    49.         imgURL = imgRegExBaseNoImage.exec(img.href)
    50.        
    51.         if (imgURL === null) {
    52.           if (img.href.indexOf('imgurl=') !== -1) {
    53.             img.style.border = '6px solid #000'
    54.             console.log('[ERROR in "rewampImgs" of google-panic-images"] The following image link could not be extracted:')
    55.             console.log(img)
    56.             console.log(img.href)
    57.           }
    58.  
    59.           continue
    60.         }
    61.       }
    62.     }
    63.    
    64.     imgURL = imgURL[1]
    65.    
    66.     let hasControls = false
    67.     for (let child of img.parentNode.childNodes) {
    68.       if (child.className === GOOGLE_PANIC_CLASS) {
    69.         hasControls = true
    70.         break
    71.       }
    72.     }
    73.  
    74.     if (hasControls) continue
    75.  
    76.     imgURL = decodeURIComponent(imgURL)
    77.     img.parentNode.addEventListener('mouseenter', overlayControls)
    78.     img.parentNode.addEventListener('mouseleave', hideControls)
    79.     img.parentNode.innerHTML += '<a target="_blank" class="' + GOOGLE_PANIC_CLASS + '" style="visibility:hidden;position:absolute;top:6%;left:0%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 8% 4px 5%;border-radius:0px 12px 12px 0px;z-index:1;font-size:12px;text-decoration:none;border:1px solid #aaa;border-left: none;" href="' + imgURL + '">VIEW</a>'
    80.   }
    81. }
    82.  
    83. // ----------------------------------------------------------------------------------------
    84. // Create / adopt the preview image link
    85.  
    86. function rewampPreviews () {
    87.   let vedSrc = document.querySelector('#irc_cb')
    88.  
    89.   if (vedSrc === null) {
    90.     return
    91.   } else if (vedSrc.dataset === undefined) {
    92.     return
    93.   } else if (vedSrc.dataset['ved'] === undefined) {
    94.     return
    95.   } else if (vedSrc.dataset['ved'].startsWith(currentVed)) {
    96.     return
    97.   }
    98.  
    99.   let previewImgs = document.querySelectorAll('img.irc_mi')
    100.     let immersiveContainers = document.querySelectorAll('div.immersive-container')  
    101.    
    102.   if (previewImgs !== null && immersiveContainers !== null) {
    103.     currentVed = document.querySelector('#irc_cb').dataset['ved'].split('_', 1)[0]
    104.  
    105.     // Assign control click commands
    106.     let gControls = document.querySelectorAll('._KKw')
    107.     for (let control of gControls) control.addEventListener('click', resetFire)
    108.    
    109.     let imgControls = document.querySelectorAll('img.irc_rii')
    110.     for (let control of imgControls) control.addEventListener('click', resetFire)
    111.    
    112.     let previewImg = null
    113.     let imgIndex = 0
    114.    
    115.     for (let container of immersiveContainers) {
    116.       if (container.dataset['ved'] !== undefined && container.dataset['ved'].startsWith(currentVed)) {
    117.         previewImg = previewImgs[imgIndex]
    118.         break
    119.       }
    120.      
    121.       ++imgIndex;
    122.     }
    123.  
    124.     if (previewImg === null) {
    125.       imgIndex = 0
    126.       for (let container of immersiveContainers) {
    127.         if (container.dataset['hveid'] !== undefined) {
    128.           previewImg = previewImgs[imgIndex]
    129.           break
    130.         }
    131.  
    132.         ++imgIndex;
    133.       }
    134.  
    135.       if (previewImg === null) {
    136.         console.log('[ERROR in "rewampPreviews" of google-panic-images] Error reading out correct large preview image link with hveid, skipping view link');
    137.         return
    138.       }
    139.     }
    140.  
    141.     let imgURLsrc = decodeURIComponent(previewImg.src)
    142.     let imgURL = imgRegExBase.exec(imgURLsrc)
    143.    
    144.     if (imgURL === null) {
    145.             imgURL = imgRegExRef.exec(imgURLsrc)
    146.      
    147.       if (imgURL === null) imgURL = imgRegExBaseNoImage.exec(imgURLsrc)
    148.     }
    149.    
    150.     if (imgURL === null) imgURL = imgURLsrc
    151.     else imgURL = imgURL[1]
    152.    
    153.     let targetContainer = document.querySelector('#irc_shc');
    154.     let hasControls = false;
    155.     for (let child of targetContainer.childNodes) {
    156.       if (child.className === GOOGLE_PANIC_CLASS) {
    157.         child.href = imgURL
    158.         hasControls = true
    159.         break
    160.       }
    161.     }
    162.  
    163.     if (!hasControls) targetContainer.innerHTML += '<a target="_blank" role="button" class="' + GOOGLE_PANIC_CLASS + '" style="cursor:pointer;visibility:visible;position:absolute;top:90%;left:30%;background:rgba(0,0,0,0.6);color:#fff;font-weight:bold;padding:7px 10px 4px 10px;border:1px solid #aaa;border-radius:12px;z-index:999;font-size:14px;text-decoration:none;" href="' + imgURL + '">VIEW</a>'
    164.   }
    165. }
    166.  
    167. // ----------------------------------------------------------------------------------------
    168. // Reschedule a parsing
    169. function resetFire () {
    170.   fireAt = Date.now() + (SECONDS_TO_FIRE_CUT * 1000);
    171.   contentHeight = 0;
    172. }
    173.  
    174. // ----------------------------------------------------------------------------------------
    175. // Function which does schedule the processing
    176. function waitForLoaded () {
    177.  
    178.   if (Date.now() > fireAt) {
    179.     let tmpHeight = document.querySelector('#cnt').clientHeight
    180.     if (contentHeight !== tmpHeight) {
    181.       contentHeight = tmpHeight
    182.       try {
    183.         rewampImgs()
    184.       } catch (e) {
    185.         console.log('[ERROR] in script, function rewampImgs ():')
    186.         console.log(e);
    187.       }
    188.     }
    189.    
    190.     try {
    191.       rewampPreviews()
    192.     } catch (e) {
    193.       console.log('[ERROR] in script, function rewampPreviews ():')
    194.       console.log(e);
    195.     }
    196.    
    197.     fireAt = Date.now() + (SECONDS_TO_FIRE * 1000)
    198.   }
    199.  
    200.   window.requestAnimationFrame(waitForLoaded)
    201. }
    202.  
    203.  
    204. // ----------------------------------------------------------------------------------------
    205. // Display the controls, when the mouse is hovered over the image
    206. function overlayControls (event) {
    207.   let img = event.target
    208.   for (let child of img.childNodes) {
    209.     if (child.className === GOOGLE_PANIC_CLASS) {
    210.       child.style.visibility = 'visible'
    211.       break
    212.     }
    213.   }
    214. }
    215.  
    216. // Hide the controls, if the mouse is moved out of the image
    217. function hideControls (event) {
    218.   let img = event.target
    219.     for (let child of img.childNodes) {
    220.     if (child.className === GOOGLE_PANIC_CLASS) {
    221.       child.style.visibility = 'hidden'
    222.       break
    223.     }
    224.   }
    225. }
    226.  
    227. // ----------------------------------------------------------------------------------------
    228. document.onreadystatechange = waitForLoaded()
    229.  
    Geändert von theSplit (20.07.18 um 08:06 Uhr) Grund: Regex überarbeitet '.' != '\.'
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  11. #11
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Zitat Zitat von Mäxchen Beitrag anzeigen
    "https://r.hswstatic.com/w_907/gif"
    Guten Morgen,

    hatte deine Edit zu spät gesehen, jetzt klappt es korrekt mit der genannten URL - selbst wenn im Namen eine mögliche Dateiendung auftritt.

    Habe die Version im vorherigen Post, nochmal geupdadet.

    Danke für das Feedback!

    Man sollte ergänzen '.' ist nicht gleich Punkt sondern nur irgendein mögliches Zeichen, hatte es nicht korrekt escaped so das es nicht '.bildFormat' erkannt hatte.
    Für diesen Beitrag bedankt sich Mäxchen
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  12. #12
    lustiger Kumpane Avatar von Mäxchen
    Registriert seit
    Jul 2013
    Ort
    am liebsten im Zelt
    Beiträge
    43

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Ja, jetzt klappt das alles wunderbar. Danke dir.
    Für diesen Beitrag bedanken sich pspzockerscene, theSplit
    33,33% aller Statistiken beruhen auf sehr kleinen Datenmengen.

  13. #13
    1998

    Veteran

    (Threadstarter)

    Avatar von theSplit
    Registriert seit
    Aug 2014
    Beiträge
    4.513
    ngb:news Artikel
    1

    Re: [Grease/Tamper] Google Bilder Direktlinks

    Das Script ist jetzt als Add-on verfügbar:

    Source, Release Opera, Chrome auf Github und Mozilla Add-ons.
    Für diesen Beitrag bedanken sich Mäxchen, pspzockerscene
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @ The past; yesterday, the present; here and now; the future; to be shaped. @
    +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •