🏠 Home 

Greasy Fork is available in English.

BingBgForGoogle

Just change the background image of Google homepage to Bing

  1. // ==UserScript==
  2. // @name BingBgForGoogle
  3. // @name:zh-CN 谷Bing图
  4. // @name:zh-TW 谷Bing圖
  5. // @namespace hoothin
  6. // @version 0.3
  7. // @description Just change the background image of Google homepage to Bing
  8. // @description:zh-CN 给谷歌首页换上 Bing 的背景图
  9. // @description:zh-TW 給 Google 首頁換上 Bing 的背景圖
  10. // @author hoothin
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_addStyle
  15. // @grant GM_registerMenuCommand
  16. // @grant unsafeWindow
  17. // @connect global.bing.com
  18. // @connect cn.bing.com
  19. // @license MIT License
  20. // @match *://www.google.com/*
  21. // @match *://www.google.ad/*
  22. // @match *://www.google.ae/*
  23. // @match *://www.google.com.af/*
  24. // @match *://www.google.com.ag/*
  25. // @match *://www.google.al/*
  26. // @match *://www.google.am/*
  27. // @match *://www.google.co.ao/*
  28. // @match *://www.google.com.ar/*
  29. // @match *://www.google.as/*
  30. // @match *://www.google.at/*
  31. // @match *://www.google.com.au/*
  32. // @match *://www.google.az/*
  33. // @match *://www.google.ba/*
  34. // @match *://www.google.com.bd/*
  35. // @match *://www.google.be/*
  36. // @match *://www.google.bf/*
  37. // @match *://www.google.bg/*
  38. // @match *://www.google.com.bh/*
  39. // @match *://www.google.bi/*
  40. // @match *://www.google.bj/*
  41. // @match *://www.google.com.bn/*
  42. // @match *://www.google.com.bo/*
  43. // @match *://www.google.com.br/*
  44. // @match *://www.google.bs/*
  45. // @match *://www.google.bt/*
  46. // @match *://www.google.co.bw/*
  47. // @match *://www.google.by/*
  48. // @match *://www.google.com.bz/*
  49. // @match *://www.google.ca/*
  50. // @match *://www.google.cd/*
  51. // @match *://www.google.cf/*
  52. // @match *://www.google.cg/*
  53. // @match *://www.google.ch/*
  54. // @match *://www.google.ci/*
  55. // @match *://www.google.co.ck/*
  56. // @match *://www.google.cl/*
  57. // @match *://www.google.cm/*
  58. // @match *://www.google.cn/*
  59. // @match *://www.google.com.co/*
  60. // @match *://www.google.co.cr/*
  61. // @match *://www.google.com.cu/*
  62. // @match *://www.google.cv/*
  63. // @match *://www.google.com.cy/*
  64. // @match *://www.google.cz/*
  65. // @match *://www.google.de/*
  66. // @match *://www.google.dj/*
  67. // @match *://www.google.dk/*
  68. // @match *://www.google.dm/*
  69. // @match *://www.google.com.do/*
  70. // @match *://www.google.dz/*
  71. // @match *://www.google.com.ec/*
  72. // @match *://www.google.ee/*
  73. // @match *://www.google.com.eg/*
  74. // @match *://www.google.es/*
  75. // @match *://www.google.com.et/*
  76. // @match *://www.google.fi/*
  77. // @match *://www.google.com.fj/*
  78. // @match *://www.google.fm/*
  79. // @match *://www.google.fr/*
  80. // @match *://www.google.ga/*
  81. // @match *://www.google.ge/*
  82. // @match *://www.google.gg/*
  83. // @match *://www.google.com.gh/*
  84. // @match *://www.google.com.gi/*
  85. // @match *://www.google.gl/*
  86. // @match *://www.google.gm/*
  87. // @match *://www.google.gr/*
  88. // @match *://www.google.com.gt/*
  89. // @match *://www.google.gy/*
  90. // @match *://www.google.com.hk/*
  91. // @match *://www.google.hn/*
  92. // @match *://www.google.hr/*
  93. // @match *://www.google.ht/*
  94. // @match *://www.google.hu/*
  95. // @match *://www.google.co.id/*
  96. // @match *://www.google.ie/*
  97. // @match *://www.google.co.il/*
  98. // @match *://www.google.im/*
  99. // @match *://www.google.co.in/*
  100. // @match *://www.google.iq/*
  101. // @match *://www.google.is/*
  102. // @match *://www.google.it/*
  103. // @match *://www.google.je/*
  104. // @match *://www.google.com.jm/*
  105. // @match *://www.google.jo/*
  106. // @match *://www.google.co.jp/*
  107. // @match *://www.google.co.ke/*
  108. // @match *://www.google.com.kh/*
  109. // @match *://www.google.ki/*
  110. // @match *://www.google.kg/*
  111. // @match *://www.google.co.kr/*
  112. // @match *://www.google.com.kw/*
  113. // @match *://www.google.kz/*
  114. // @match *://www.google.la/*
  115. // @match *://www.google.com.lb/*
  116. // @match *://www.google.li/*
  117. // @match *://www.google.lk/*
  118. // @match *://www.google.co.ls/*
  119. // @match *://www.google.lt/*
  120. // @match *://www.google.lu/*
  121. // @match *://www.google.lv/*
  122. // @match *://www.google.com.ly/*
  123. // @match *://www.google.co.ma/*
  124. // @match *://www.google.md/*
  125. // @match *://www.google.me/*
  126. // @match *://www.google.mg/*
  127. // @match *://www.google.mk/*
  128. // @match *://www.google.ml/*
  129. // @match *://www.google.com.mm/*
  130. // @match *://www.google.mn/*
  131. // @match *://www.google.com.mt/*
  132. // @match *://www.google.mu/*
  133. // @match *://www.google.mv/*
  134. // @match *://www.google.mw/*
  135. // @match *://www.google.com.mx/*
  136. // @match *://www.google.com.my/*
  137. // @match *://www.google.co.mz/*
  138. // @match *://www.google.com.na/*
  139. // @match *://www.google.com.ng/*
  140. // @match *://www.google.com.ni/*
  141. // @match *://www.google.ne/*
  142. // @match *://www.google.nl/*
  143. // @match *://www.google.no/*
  144. // @match *://www.google.com.np/*
  145. // @match *://www.google.nr/*
  146. // @match *://www.google.nu/*
  147. // @match *://www.google.co.nz/*
  148. // @match *://www.google.com.om/*
  149. // @match *://www.google.com.pa/*
  150. // @match *://www.google.com.pe/*
  151. // @match *://www.google.com.pg/*
  152. // @match *://www.google.com.ph/*
  153. // @match *://www.google.com.pk/*
  154. // @match *://www.google.pl/*
  155. // @match *://www.google.pn/*
  156. // @match *://www.google.com.pr/*
  157. // @match *://www.google.ps/*
  158. // @match *://www.google.pt/*
  159. // @match *://www.google.com.py/*
  160. // @match *://www.google.com.qa/*
  161. // @match *://www.google.ro/*
  162. // @match *://www.google.ru/*
  163. // @match *://www.google.rw/*
  164. // @match *://www.google.com.sa/*
  165. // @match *://www.google.com.sb/*
  166. // @match *://www.google.sc/*
  167. // @match *://www.google.se/*
  168. // @match *://www.google.com.sg/*
  169. // @match *://www.google.sh/*
  170. // @match *://www.google.si/*
  171. // @match *://www.google.sk/*
  172. // @match *://www.google.com.sl/*
  173. // @match *://www.google.sn/*
  174. // @match *://www.google.so/*
  175. // @match *://www.google.sm/*
  176. // @match *://www.google.sr/*
  177. // @match *://www.google.st/*
  178. // @match *://www.google.com.sv/*
  179. // @match *://www.google.td/*
  180. // @match *://www.google.tg/*
  181. // @match *://www.google.co.th/*
  182. // @match *://www.google.com.tj/*
  183. // @match *://www.google.tl/*
  184. // @match *://www.google.tm/*
  185. // @match *://www.google.tn/*
  186. // @match *://www.google.to/*
  187. // @match *://www.google.com.tr/*
  188. // @match *://www.google.tt/*
  189. // @match *://www.google.com.tw/*
  190. // @match *://www.google.co.tz/*
  191. // @match *://www.google.com.ua/*
  192. // @match *://www.google.co.ug/*
  193. // @match *://www.google.co.uk/*
  194. // @match *://www.google.com.uy/*
  195. // @match *://www.google.co.uz/*
  196. // @match *://www.google.com.vc/*
  197. // @match *://www.google.co.ve/*
  198. // @match *://www.google.co.vi/*
  199. // @match *://www.google.com.vn/*
  200. // @match *://www.google.vu/*
  201. // @match *://www.google.ws/*
  202. // @match *://www.google.rs/*
  203. // @match *://www.google.co.za/*
  204. // @match *://www.google.co.zm/*
  205. // @match *://www.google.co.zw/*
  206. // @match *://www.google.cat/*
  207. // ==/UserScript==
  208. (function() {
  209. 'use strict';
  210. if (/\?q=/.test(location.href)) return;
  211. let LinkPa = document.querySelector("[data-ogbl]");
  212. if (!LinkPa) return;
  213. let bingBgLink = document.createElement("a");
  214. bingBgLink.className = LinkPa.firstChild.firstChild.className;
  215. bingBgLink.target = "_blank";
  216. bingBgLink.innerText = "Bing Bg";
  217. let linkDiv = document.createElement("div");
  218. linkDiv.className = LinkPa.firstChild.className;
  219. linkDiv.appendChild(bingBgLink);
  220. LinkPa.appendChild(linkDiv);
  221. let skinContainer = document.body;
  222. GM_addStyle(`
  223. body{
  224. background-position: center 0;
  225. background-repeat: no-repeat;
  226. background-size: cover;
  227. -webkit-background-size: cover;
  228. -o-background-size: cover;
  229. }
  230. #gb{
  231. background-color: unset!important;
  232. }
  233. [role="navigation"],[role="contentinfo"]{
  234. background-color: rgb(32 33 36 / 50%)!important;
  235. }
  236. #gb *,[role="contentinfo"] *{
  237. color: white!important;
  238. }
  239. `);
  240. let btnK = document.querySelector("input[name='btnK']");
  241. let clickHandler = e => {
  242. skinContainer.style.backgroundImage = "";
  243. };
  244. btnK.addEventListener("click",clickHandler);
  245. let bingImgObj = GM_getValue("bingImgObj");
  246. if (bingImgObj) {
  247. skinContainer.style.backgroundImage = "url(\"" + bingImgObj.base64 + "\")";
  248. }
  249. GM_xmlhttpRequest({
  250. method: 'GET',
  251. url: "https://global.bing.com/HPImageArchive.aspx?format=js&idx=0&pid=hp&video=1&n=1",
  252. onload: function(r###lt) {
  253. let jsonData = null;
  254. try {
  255. jsonData = JSON.parse(r###lt.responseText);
  256. let bgUrl = jsonData.images[0].url;
  257. if (!/^https?:\/\//.test(bgUrl)) {
  258. bgUrl = "https://global.bing.com" + bgUrl;
  259. }
  260. bingBgLink.title = jsonData.images[0].copyright;
  261. bingBgLink.href = bgUrl;
  262. if (bingImgObj && bingImgObj.url == bgUrl) return;
  263. if (!bingImgObj) skinContainer.style.backgroundImage = "url(\"" + bgUrl + "\")";
  264. GM_xmlhttpRequest({
  265. method: 'GET',
  266. url: bgUrl,
  267. responseType: "blob",
  268. onload: function(r) {
  269. let blob = r.response;
  270. let fr = new FileReader();
  271. fr.readAsDataURL(blob);
  272. fr.onload = function (e) {
  273. let base64ImgData = e.target.r###lt;
  274. GM_setValue("bingImgObj",{url: bgUrl, base64: base64ImgData});
  275. };
  276. }
  277. });
  278. } catch (e) {
  279. console.log(e);
  280. }
  281. }
  282. });
  283. let blurStyle;
  284. function createBlur() {
  285. if (!blurStyle) {
  286. blurStyle = document.createElement("style");
  287. blurStyle.innerText = `
  288. body::before{
  289. content: " ";
  290. display: block;
  291. position: absolute;
  292. left: 0;
  293. top: 0;
  294. right: 0;
  295. bottom: 0;
  296. background: inherit;
  297. filter: blur(5px);
  298. z-index: -1;
  299. }`;
  300. }
  301. document.head.appendChild(blurStyle);
  302. }
  303. if (GM_getValue("blur")) {
  304. createBlur();
  305. }
  306. GM_registerMenuCommand("Change blur", () => {
  307. if (blurStyle && blurStyle.parentNode) {
  308. GM_setValue("blur", false);
  309. blurStyle.parentNode.removeChild(blurStyle);
  310. } else {
  311. GM_setValue("blur", true);
  312. createBlur();
  313. }
  314. });
  315. })();