├── README.md ├── icon128.png ├── icon16.png ├── icon48.png ├── manifest.json └── run.user.js /README.md: -------------------------------------------------------------------------------- 1 | # Google Image Sizer 2 | Simple Chrome extension to re-implement Google Images size filter (e.g. Larger than 2MP)
3 | Download [here for Chrome](https://chrome.google.com/webstore/detail/google-image-sizer/pkfdieeblkapoopkmlpnnlepnblgbphk) or [here for Firefox](https://addons.mozilla.org/en-US/firefox/addon/google-image-sizer/). 4 | -------------------------------------------------------------------------------- /icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danieljbingham/google-image-sizer/1070b08115b99f3c36f7b517d64b9132e481c27d/icon128.png -------------------------------------------------------------------------------- /icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danieljbingham/google-image-sizer/1070b08115b99f3c36f7b517d64b9132e481c27d/icon16.png -------------------------------------------------------------------------------- /icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danieljbingham/google-image-sizer/1070b08115b99f3c36f7b517d64b9132e481c27d/icon48.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Image Search Sizer", 4 | "version": "2.0.1", 5 | "description": "Re-implements Google\u2122 image search feature to filter images by megapixels.", 6 | "icons": { 7 | "128": "icon128.png", 8 | "48": "icon48.png", 9 | "16": "icon16.png" 10 | }, 11 | "browser_specific_settings": { 12 | "gecko": { 13 | "id": "{26154796-e7a2-4ffe-b56e-3433760cd824}" 14 | } 15 | }, 16 | "content_scripts": [ 17 | { 18 | "matches": [ 19 | "*://*.google.com/*", 20 | "*://*.google.ac/*", 21 | "*://*.google.ad/*", 22 | "*://*.google.com.af/*", 23 | "*://*.google.com.ag/*", 24 | "*://*.google.com.ai/*", 25 | "*://*.google.am/*", 26 | "*://*.google.it.ao/*", 27 | "*://*.google.com.ar/*", 28 | "*://*.google.as/*", 29 | "*://*.google.at/*", 30 | "*://*.google.com.au/*", 31 | "*://*.google.az/*", 32 | "*://*.google.ba/*", 33 | "*://*.google.com.bd/*", 34 | "*://*.google.be/*", 35 | "*://*.google.bf/*", 36 | "*://*.google.bg/*", 37 | "*://*.google.com.bh/*", 38 | "*://*.google.bi/*", 39 | "*://*.google.bj/*", 40 | "*://*.google.com.bn/*", 41 | "*://*.google.com.bo/*", 42 | "*://*.google.com.br/*", 43 | "*://*.google.bs/*", 44 | "*://*.google.co.bw/*", 45 | "*://*.google.com.by/*", 46 | "*://*.google.by/*", 47 | "*://*.google.com.bz/*", 48 | "*://*.google.ca/*", 49 | "*://*.google.com.kh/*", 50 | "*://*.google.cc/*", 51 | "*://*.google.cd/*", 52 | "*://*.google.cf/*", 53 | "*://*.google.cat/*", 54 | "*://*.google.cg/*", 55 | "*://*.google.ch/*", 56 | "*://*.google.ci/*", 57 | "*://*.google.co.ck/*", 58 | "*://*.google.cl/*", 59 | "*://*.google.cm/*", 60 | "*://*.google.cn/*", 61 | "*://*.google.com.co/*", 62 | "*://*.google.co.cr/*", 63 | "*://*.google.com.cu/*", 64 | "*://*.google.cv/*", 65 | "*://*.google.com.cy/*", 66 | "*://*.google.cz/*", 67 | "*://*.google.de/*", 68 | "*://*.google.dj/*", 69 | "*://*.google.dk/*", 70 | "*://*.google.dm/*", 71 | "*://*.google.com.do/*", 72 | "*://*.google.dz/*", 73 | "*://*.google.com.ec/*", 74 | "*://*.google.ee/*", 75 | "*://*.google.com.eg/*", 76 | "*://*.google.es/*", 77 | "*://*.google.com.et/*", 78 | "*://*.google.fi/*", 79 | "*://*.google.com.fj/*", 80 | "*://*.google.fm/*", 81 | "*://*.google.fr/*", 82 | "*://*.google.ga/*", 83 | "*://*.google.gd/*", 84 | "*://*.google.ge/*", 85 | "*://*.google.gf/*", 86 | "*://*.google.gg/*", 87 | "*://*.google.com.gh/*", 88 | "*://*.google.com.gi/*", 89 | "*://*.google.gl/*", 90 | "*://*.google.gm/*", 91 | "*://*.google.gp/*", 92 | "*://*.google.gr/*", 93 | "*://*.google.com.gt/*", 94 | "*://*.google.gy/*", 95 | "*://*.google.com.hk/*", 96 | "*://*.google.hn/*", 97 | "*://*.google.hr/*", 98 | "*://*.google.ht/*", 99 | "*://*.google.hu/*", 100 | "*://*.google.co.id/*", 101 | "*://*.google.iq/*", 102 | "*://*.google.ie/*", 103 | "*://*.google.co.il/*", 104 | "*://*.google.im/*", 105 | "*://*.google.co.in/*", 106 | "*://*.google.io/*", 107 | "*://*.google.is/*", 108 | "*://*.google.it/*", 109 | "*://*.google.je/*", 110 | "*://*.google.com.jm/*", 111 | "*://*.google.jo/*", 112 | "*://*.google.co.jp/*", 113 | "*://*.google.co.ke/*", 114 | "*://*.google.com.kh/*", 115 | "*://*.google.ki/*", 116 | "*://*.google.kg/*", 117 | "*://*.google.co.kr/*", 118 | "*://*.google.com.kw/*", 119 | "*://*.google.kz/*", 120 | "*://*.google.la/*", 121 | "*://*.google.com.lb/*", 122 | "*://*.google.com.lc/*", 123 | "*://*.google.li/*", 124 | "*://*.google.lk/*", 125 | "*://*.google.co.ls/*", 126 | "*://*.google.lt/*", 127 | "*://*.google.lu/*", 128 | "*://*.google.lv/*", 129 | "*://*.google.com.ly/*", 130 | "*://*.google.co.ma/*", 131 | "*://*.google.md/*", 132 | "*://*.google.me/*", 133 | "*://*.google.mg/*", 134 | "*://*.google.mk/*", 135 | "*://*.google.ml/*", 136 | "*://*.google.mn/*", 137 | "*://*.google.ms/*", 138 | "*://*.google.com.mt/*", 139 | "*://*.google.mu/*", 140 | "*://*.google.mv/*", 141 | "*://*.google.mw/*", 142 | "*://*.google.com.mx/*", 143 | "*://*.google.com.my/*", 144 | "*://*.google.co.mz/*", 145 | "*://*.google.com.na/*", 146 | "*://*.google.ne/*", 147 | "*://*.google.com.nf/*", 148 | "*://*.google.com.ng/*", 149 | "*://*.google.com.ni/*", 150 | "*://*.google.nl/*", 151 | "*://*.google.no/*", 152 | "*://*.google.com.np/*", 153 | "*://*.google.nr/*", 154 | "*://*.google.nu/*", 155 | "*://*.google.co.nz/*", 156 | "*://*.google.com.om/*", 157 | "*://*.google.com.pa/*", 158 | "*://*.google.com.pe/*", 159 | "*://*.google.com.ph/*", 160 | "*://*.google.com.pk/*", 161 | "*://*.google.pl/*", 162 | "*://*.google.pn/*", 163 | "*://*.google.com.pr/*", 164 | "*://*.google.ps/*", 165 | "*://*.google.pt/*", 166 | "*://*.google.com.py/*", 167 | "*://*.google.com.qa/*", 168 | "*://*.google.ro/*", 169 | "*://*.google.rs/*", 170 | "*://*.google.ru/*", 171 | "*://*.google.rw/*", 172 | "*://*.google.com.sa/*", 173 | "*://*.google.com.sb/*", 174 | "*://*.google.sc/*", 175 | "*://*.google.se/*", 176 | "*://*.google.com.sg/*", 177 | "*://*.google.sh/*", 178 | "*://*.google.si/*", 179 | "*://*.google.sk/*", 180 | "*://*.google.com.sl/*", 181 | "*://*.google.sn/*", 182 | "*://*.google.sm/*", 183 | "*://*.google.so/*", 184 | "*://*.google.st/*", 185 | "*://*.google.com.sv/*", 186 | "*://*.google.td/*", 187 | "*://*.google.tg/*", 188 | "*://*.google.co.th/*", 189 | "*://*.google.com.tj/*", 190 | "*://*.google.tk/*", 191 | "*://*.google.tl/*", 192 | "*://*.google.tm/*", 193 | "*://*.google.to/*", 194 | "*://*.google.com.tn/*", 195 | "*://*.google.com.tr/*", 196 | "*://*.google.tt/*", 197 | "*://*.google.com.tw/*", 198 | "*://*.google.co.tz/*", 199 | "*://*.google.com.ua/*", 200 | "*://*.google.co.ug/*", 201 | "*://*.google.ae/*", 202 | "*://*.google.co.uk/*", 203 | "*://*.google.us/*", 204 | "*://*.google.com.uy/*", 205 | "*://*.google.co.uz/*", 206 | "*://*.google.com.vc/*", 207 | "*://*.google.co.ve/*", 208 | "*://*.google.vg/*", 209 | "*://*.google.co.vi/*", 210 | "*://*.google.com.vn/*", 211 | "*://*.google.vu/*", 212 | "*://*.google.ws/*", 213 | "*://*.google.co.za/*", 214 | "*://*.google.co.zm/*", 215 | "*://*.google.co.zw/*" 216 | ], 217 | "js": [ 218 | "run.user.js" 219 | ] 220 | } 221 | ] 222 | } -------------------------------------------------------------------------------- /run.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Google image sizer 3 | // @namespace https://github.com/danieljbingham/google-image-sizer 4 | // @version 2.0.1 5 | // @description re-implement Google Images size filter 6 | // @author Daniel Bingham 7 | // @include http*://*.google.tld/search*tbm=isch* 8 | // @grant none 9 | // ==/UserScript== 10 | 11 | (function () { 12 | 13 | var sizes = ["2mp", "4mp", "6mp", "8mp", "10mp", "12mp", "15mp", "20mp", "40mp", "70mp"]; 14 | 15 | /* 16 | Add sizes for current Google Images layout 17 | */ 18 | function addSizes() { 19 | // Select the g-menu with the specific jsname attribute 20 | const menu = document.querySelector('g-menu[jsname="xl07Ob"]'); 21 | console.log("Adding Google Image sizes...") 22 | 23 | // Check if the menu exists 24 | if (menu) { 25 | // Select the last g-menu-item within this menu 26 | const lastMenuItem = menu.querySelector('g-menu-item:last-child'); 27 | 28 | // Url size param 29 | const sizeParameter = window.location.href.match(/imgsz=([^&]+)/); 30 | const currentSize = sizeParameter && sizeParameter.length > 1 ? sizeParameter[1] : null 31 | console.log(`Current URL is ${currentSize}`); 32 | 33 | const checkedMenuItem = menu.querySelector('g-menu-item div[aria-checked="true"]').closest('g-menu-item'); 34 | 35 | if (currentSize) { 36 | // Uncheck any aria-checked nodes 37 | const checkedNodes = menu.querySelectorAll('[aria-checked="true"]'); 38 | checkedNodes.forEach(node => node.setAttribute('aria-checked', 'false')); 39 | } 40 | 41 | sizes.forEach(size => { 42 | 43 | if (currentSize == size) { 44 | console.log(`${size} should be checked`) 45 | 46 | const newMenuItem = checkedMenuItem.cloneNode(true); 47 | console.log("newMenuItem") 48 | console.log(newMenuItem) 49 | const newAnchor = newMenuItem.querySelector('.y0fQ9c'); 50 | newAnchor.textContent = `Larger than ${size}`; 51 | newAnchor.setAttribute('aria-checked', 'true'); 52 | 53 | menu.appendChild(newMenuItem); 54 | } else { 55 | console.log(`${size} should NOT be checked`) 56 | 57 | const newMenuItem = lastMenuItem.cloneNode(true); 58 | const newAnchor = newMenuItem.querySelector('a'); 59 | newAnchor.href = newAnchor.href.replace(/tbs=isz:[^&]+/, "imgsz=" + size); 60 | 61 | // Remove all occurrences of tbs=isz: and imgsz= 62 | newAnchor.href = newAnchor.href.replace(/(tbs=isz:[^&]+|imgsz=[^&]+)/g, ""); 63 | 64 | // Append the new imgsz parameter 65 | newAnchor.href += (newAnchor.href.includes("?") ? "&" : "?") + "imgsz=" + size; 66 | 67 | newAnchor.textContent = `Larger than ${size}`; 68 | newAnchor.setAttribute('aria-checked', 'false'); 69 | 70 | menu.appendChild(newMenuItem); 71 | } 72 | 73 | 74 | console.log(`New menu item for size ${size} added!`); 75 | }) 76 | 77 | } else { 78 | console.error('Menu with jsname "xl07Ob" not found.'); 79 | } 80 | } 81 | 82 | /* 83 | Check the user is on google images 84 | */ 85 | function isImageUrl() { 86 | return document.querySelector('div[jsname="bVqjv"][selected]') || location.href.includes("tbm=isch"); 87 | } 88 | 89 | /* 90 | Check sizes not there already 91 | */ 92 | function needSizes() { 93 | var nodes = document.querySelector('g-menu[jsname="xl07Ob"]'); 94 | return nodes && nodes.childNodes.length < 6; 95 | } 96 | 97 | /* 98 | Show sizes/dimensions by default instead of on hover 99 | TODO: no longer works, google doesn't show dimensions at all unless image clicked 100 | */ 101 | function showSizesDefault() { 102 | var css = ".rg_anbg {display: none !important;} .rg_l:hover .rg_anbg {display: block !important;} " + 103 | ".rg_ilmbg {display: block !important;} .rg_l:hover .rg_ilmbg {display: none !important;}" + 104 | ".h312td.RtIwE {display:block;} .isv-r.MSM1fd:hover .h312td.RtIwE {display: none;}"; 105 | var style = document.createElement('style'); 106 | 107 | if (style.styleSheet) { 108 | style.styleSheet.cssText = css; 109 | } else { 110 | style.appendChild(document.createTextNode(css)); 111 | } 112 | 113 | document.getElementsByTagName('head')[0].appendChild(style); 114 | } 115 | 116 | //run script 117 | showSizesDefault(); 118 | 119 | var maxTries = 100; 120 | function chk() { 121 | if (!document.querySelector('g-menu[jsname="xl07Ob"]')) { 122 | if (maxTries--) setTimeout(chk, 100); 123 | return; 124 | } 125 | 126 | if (needSizes()) addSizes(); 127 | } 128 | 129 | if (isImageUrl()) chk(); 130 | 131 | })(); 132 | --------------------------------------------------------------------------------