图寻-隐藏街景车和指南针

去除图寻街景车。使用Shift+K切换指南针。移植自GeoNoCar by 2020, drparse。

当前为 2024-06-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TuxunNoCar
  3. // @name:zh-CN 图寻-隐藏街景车和指南针
  4. // @description Redacts the car from tuxun, the Chinese geoguessr. Shift-K to toggle compass. Transplanted from GeoNoCar by 2020, drparse.
  5. // @description:zh-CN 去除图寻街景车。使用Shift+K切换指南针。移植自GeoNoCar by 2020, drparse。
  6. // @namespace https://tuxun.fun/
  7. // @version 0.1.1
  8. // @author strombooli
  9. // @match https://tuxun.fun/*
  10. // @exclude https://tuxun.fun/replay-pano?*
  11. // @exclude https://tuxun.fun/wonders
  12. // @exclude https://tuxun.fun/random
  13. // @grant unsafeWindow
  14. // @run-at document-start
  15. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  16. // @noframes
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. function injected() {
  23. const OPTIONS = {
  24. colorR: 0.5,
  25. colorG: 0.5,
  26. colorB: 0.5,
  27. };
  28.  
  29. // If the script breaks, search devtools for "BINTULU" and replace these lines with the new one
  30. const vertexOld = "const float f=3.1415926;varying vec3 a;uniform vec4 b;attribute vec3 c;attribute vec2 d;uniform mat4 e;void main(){vec4 g=vec4(c,1);gl_Position=e*g;a=vec3(d.xy*b.xy+b.zw,1);a*=length(c);}";
  31. const fragOld = "precision highp float;const float h=3.1415926;varying vec3 a;uniform vec4 b;uniform float f;uniform sampler2D g;void main(){vec4 i=vec4(texture2DProj(g,a).rgb,f);gl_FragColor=i;}";
  32.  
  33. const vertexNew = `
  34. const float f=3.1415926;
  35. varying vec3 a;
  36. varying vec3 potato;
  37. uniform vec4 b;
  38. attribute vec3 c;
  39. attribute vec2 d;
  40. uniform mat4 e;
  41. void main(){
  42. vec4 g=vec4(c,1);
  43. gl_Position=e*g;
  44. a = vec3(d.xy * b.xy + b.zw,1);
  45. a *= length(c);
  46.  
  47. potato = vec3(d.xy, 1.0) * length(c);
  48. }`;
  49. const fragNewBaidu = `precision highp float;
  50. const float h=3.1415926;
  51. varying vec3 a;
  52. varying vec3 potato;
  53. uniform vec4 b;
  54. uniform float f;
  55. uniform sampler2D g;
  56. void main(){
  57.  
  58. vec2 aD = potato.xy / a.z;
  59. float thetaD = aD.y;
  60.  
  61. float thresholdD1 = 0.62;
  62. float thresholdD2 = 0.62;
  63.  
  64. float x = aD.x;
  65. float y = abs(4.0*x - 2.0);
  66. float phiD = smoothstep(0.0, 1.0, y > 1.0 ? 2.0 - y : y);
  67.  
  68. vec4 i = vec4(
  69. thetaD > mix(thresholdD1, thresholdD2, phiD)
  70. ? vec3(float(${OPTIONS.colorR}), float(${OPTIONS.colorG}), float(${OPTIONS.colorB})) // texture2DProj(g,a).rgb * 0.25
  71. : texture2DProj(g,a).rgb
  72. ,f);
  73. gl_FragColor=i;
  74. }`;
  75.  
  76. const fragNew = `precision highp float;
  77. const float h=3.1415926;
  78. varying vec3 a;
  79. varying vec3 potato;
  80. uniform vec4 b;
  81. uniform float f;
  82. uniform sampler2D g;
  83. void main(){
  84.  
  85. vec2 aD = potato.xy / a.z;
  86. float thetaD = aD.y;
  87.  
  88. float thresholdD1 = 0.6;
  89. float thresholdD2 = 0.7;
  90.  
  91. float x = aD.x;
  92. float y = abs(4.0*x - 2.0);
  93. float phiD = smoothstep(0.0, 1.0, y > 1.0 ? 2.0 - y : y);
  94.  
  95. vec4 i = vec4(
  96. thetaD > mix(thresholdD1, thresholdD2, phiD)
  97. ? vec3(float(${OPTIONS.colorR}), float(${OPTIONS.colorG}), float(${OPTIONS.colorB})) // texture2DProj(g,a).rgb * 0.25
  98. : texture2DProj(g,a).rgb
  99. ,f);
  100. gl_FragColor=i;
  101. }`;
  102.  
  103. function isBaidu(){
  104. return document.getElementsByClassName("panorama___kKSrn")[0].children.length == 2;
  105. }
  106.  
  107. function installShaderSource(ctx) {
  108. const g = ctx.shaderSource;
  109. function shaderSource() {
  110. if (typeof arguments[1] === 'string') {
  111. let glsl = arguments[1];
  112. console.log('BINTULU shader', glsl);
  113.  
  114. if (glsl === vertexOld) glsl = vertexNew;
  115. else if (glsl === fragOld){
  116. if (isBaidu()) glsl = fragNewBaidu;
  117. else glsl = fragNew;
  118. }
  119. return g.call(this, arguments[0], glsl);
  120. }
  121. return g.apply(this, arguments);
  122. }
  123. shaderSource.bestcity = 'bintulu';
  124. ctx.shaderSource = shaderSource;
  125. }
  126. function installGetContext(el) {
  127. const g = el.getContext;
  128. el.getContext = function() {
  129. if (arguments[0] === 'webgl' || arguments[0] === 'webgl2') {
  130. const ctx = g.apply(this, arguments);
  131. if (ctx && ctx.shaderSource && ctx.shaderSource.bestcity !== 'bintulu') {
  132. installShaderSource(ctx);
  133. }
  134. return ctx;
  135. }
  136. return g.apply(this, arguments);
  137. };
  138. }
  139. const f = document.createElement;
  140. document.createElement = function() {
  141. if (arguments[0] === 'canvas' || arguments[0] === 'CANVAS') {
  142. const el = f.apply(this, arguments);
  143. installGetContext(el);
  144. return el;
  145. }
  146. return f.apply(this, arguments);
  147. };
  148. function addCompassStyle() {
  149. let style = document.createElement('style');
  150. style.id = 'bintulu_nocompass';
  151. style.innerHTML = '.gmnoprint.gm-bundled-control.gm-bundled-control-on-bottom { display: none }';
  152. document.head.appendChild(style);
  153. }
  154. addCompassStyle();
  155. document.addEventListener('keydown', (evt) => {
  156. if (!evt.repeat && evt.code === 'KeyK' && evt.shiftKey && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  157. let style = document.getElementById('bintulu_nocompass');
  158. if (!style) {
  159. addCompassStyle();
  160. } else {
  161. style.remove();
  162. }
  163. }
  164. });
  165. }
  166.  
  167. unsafeWindow.eval(`(${injected.toString()})()`);
  168.  
  169. })();