Microsoft Update Catalog - Auto Highlight the version for your OS

Auto Highlight the version for your OS when you download the updates from Microsoft Update Catalog

  1. // ==UserScript==
  2. // @name Microsoft Update Catalog - Auto Highlight the version for your OS
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Auto Highlight the version for your OS when you download the updates from Microsoft Update Catalog
  6. // @author You
  7. // @match https://www.catalog.update.microsoft.com/*
  8. // @icon https://www.google.com/s2/favicons?domain=microsoft.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function $$() {
  13. 'use strict';
  14.  
  15. if(!document.documentElement) return window.requestAnimationFrame($$);
  16.  
  17.  
  18. function addStyle(styleText) {
  19. const styleNode = document.createElement('style');
  20. styleNode.type = 'text/css';
  21. styleNode.textContent = styleText;
  22. document.documentElement.appendChild(styleNode);
  23. return styleNode;
  24. }
  25.  
  26. const cssText=`
  27. [ms-update-highlighted-row] td{
  28. font-weight:900;
  29. }
  30. [ms-update-highlighted-row] td input:only-of-type{
  31. font-weight:600;
  32. background-color:rgba(100,135,220,0.3);
  33. }
  34.  
  35. `
  36.  
  37.  
  38. function isIntelX64(){
  39. // https://stackoverflow.com/a/13709431/6764107
  40.  
  41. if(!window.navigator)return null;
  42.  
  43. let ua= navigator.userAgent;
  44. if(!ua || typeof ua !='string')return null;
  45.  
  46. let kua = ua.replace(/64\d/g,'').replace(/\s*[;,]\s*/,'$1 ')
  47.  
  48. let res1 = /x86_64|x86\-64|Win64|x64;|amd64|AMD64|WOW64|x64_64/.test(kua);
  49. let res2 = /ia64|sparc64|ppc64|IRIX64/.test(kua);
  50.  
  51. return res1 && !res2;
  52.  
  53. }
  54.  
  55.  
  56.  
  57. /* DEMO http://jsfiddle.net/rLnwg3vy/ */
  58.  
  59. /**
  60. * JavaScript Client Detection
  61. * (C) viazenetti GmbH (Christian Ludwig)
  62. */
  63. function getJSCD () {
  64. {
  65. let screen = window.screen;
  66. var unknown = '-';
  67.  
  68. // screen
  69. var screenSize = '';
  70. if (screen && screen.width) {
  71. let width = (screen.width) ? screen.width : '';
  72. let height = (screen.height) ? screen.height : '';
  73. screenSize += '' + width + " x " + height;
  74. }
  75.  
  76. // browser
  77. var nVer = navigator.appVersion;
  78. var nAgt = navigator.userAgent;
  79. var browser = navigator.appName;
  80. var version = '' + parseFloat(navigator.appVersion);
  81. var majorVersion = parseInt(navigator.appVersion, 10);
  82. var nameOffset, verOffset, ix;
  83.  
  84. // Opera
  85. if ((verOffset = nAgt.indexOf('Opera')) != -1) {
  86. browser = 'Opera';
  87. version = nAgt.substring(verOffset + 6);
  88. if ((verOffset = nAgt.indexOf('Version')) != -1) {
  89. version = nAgt.substring(verOffset + 8);
  90. }
  91. }
  92. // Opera Next
  93. if ((verOffset = nAgt.indexOf('OPR')) != -1) {
  94. browser = 'Opera';
  95. version = nAgt.substring(verOffset + 4);
  96. }
  97. // Legacy Edge
  98. else if ((verOffset = nAgt.indexOf('Edge')) != -1) {
  99. browser = 'Microsoft Legacy Edge';
  100. version = nAgt.substring(verOffset + 5);
  101. }
  102. // Edge (Chromium)
  103. else if ((verOffset = nAgt.indexOf('Edg')) != -1) {
  104. browser = 'Microsoft Edge';
  105. version = nAgt.substring(verOffset + 4);
  106. }
  107. // MSIE
  108. else if ((verOffset = nAgt.indexOf('MSIE')) != -1) {
  109. browser = 'Microsoft Internet Explorer';
  110. version = nAgt.substring(verOffset + 5);
  111. }
  112. // Chrome
  113. else if ((verOffset = nAgt.indexOf('Chrome')) != -1) {
  114. browser = 'Chrome';
  115. version = nAgt.substring(verOffset + 7);
  116. }
  117. // Safari
  118. else if ((verOffset = nAgt.indexOf('Safari')) != -1) {
  119. browser = 'Safari';
  120. version = nAgt.substring(verOffset + 7);
  121. if ((verOffset = nAgt.indexOf('Version')) != -1) {
  122. version = nAgt.substring(verOffset + 8);
  123. }
  124. }
  125. // Firefox
  126. else if ((verOffset = nAgt.indexOf('Firefox')) != -1) {
  127. browser = 'Firefox';
  128. version = nAgt.substring(verOffset + 8);
  129. }
  130. // MSIE 11+
  131. else if (nAgt.indexOf('Trident/') != -1) {
  132. browser = 'Microsoft Internet Explorer';
  133. version = nAgt.substring(nAgt.indexOf('rv:') + 3);
  134. }
  135. // Other browsers
  136. else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
  137. browser = nAgt.substring(nameOffset, verOffset);
  138. version = nAgt.substring(verOffset + 1);
  139. if (browser.toLowerCase() == browser.toUpperCase()) {
  140. browser = navigator.appName;
  141. }
  142. }
  143. // trim the version string
  144. if ((ix = version.indexOf(';')) != -1) version = version.substring(0, ix);
  145. if ((ix = version.indexOf(' ')) != -1) version = version.substring(0, ix);
  146. if ((ix = version.indexOf(')')) != -1) version = version.substring(0, ix);
  147.  
  148. majorVersion = parseInt('' + version, 10);
  149. if (isNaN(majorVersion)) {
  150. version = '' + parseFloat(navigator.appVersion);
  151. majorVersion = parseInt(navigator.appVersion, 10);
  152. }
  153.  
  154. // mobile version
  155. var mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
  156.  
  157. // cookie
  158. var cookieEnabled = (navigator.cookieEnabled) ? true : false;
  159.  
  160. if (typeof navigator.cookieEnabled == 'undefined' && !cookieEnabled) {
  161. document.cookie = 'testcookie';
  162. cookieEnabled = (document.cookie.indexOf('testcookie') != -1) ? true : false;
  163. }
  164.  
  165. // system
  166. var os = unknown;
  167. var clientStrings = [
  168. {s:'Windows 10', r:/(Windows 10.0|Windows NT 10.0)/},
  169. {s:'Windows 8.1', r:/(Windows 8.1|Windows NT 6.3)/},
  170. {s:'Windows 8', r:/(Windows 8|Windows NT 6.2)/},
  171. {s:'Windows 7', r:/(Windows 7|Windows NT 6.1)/},
  172. {s:'Windows Vista', r:/Windows NT 6.0/},
  173. {s:'Windows Server 2003', r:/Windows NT 5.2/},
  174. {s:'Windows XP', r:/(Windows NT 5.1|Windows XP)/},
  175. {s:'Windows 2000', r:/(Windows NT 5.0|Windows 2000)/},
  176. {s:'Windows ME', r:/(Win 9x 4.90|Windows ME)/},
  177. {s:'Windows 98', r:/(Windows 98|Win98)/},
  178. {s:'Windows 95', r:/(Windows 95|Win95|Windows_95)/},
  179. {s:'Windows NT 4.0', r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},
  180. {s:'Windows CE', r:/Windows CE/},
  181. {s:'Windows 3.11', r:/Win16/},
  182. {s:'Android', r:/Android/},
  183. {s:'Open BSD', r:/OpenBSD/},
  184. {s:'Sun OS', r:/SunOS/},
  185. {s:'Chrome OS', r:/CrOS/},
  186. {s:'Linux', r:/(Linux|X11(?!.*CrOS))/},
  187. {s:'iOS', r:/(iPhone|iPad|iPod)/},
  188. {s:'Mac OS X', r:/Mac OS X/},
  189. {s:'Mac OS', r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},
  190. {s:'QNX', r:/QNX/},
  191. {s:'UNIX', r:/UNIX/},
  192. {s:'BeOS', r:/BeOS/},
  193. {s:'OS/2', r:/OS\/2/},
  194. {s:'Search Bot', r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}
  195. ];
  196. for (var id in clientStrings) {
  197. var cs = clientStrings[id];
  198. if (cs.r.test(nAgt)) {
  199. os = cs.s;
  200. break;
  201. }
  202. }
  203.  
  204. var osVersion = unknown;
  205.  
  206. if (/Windows/.test(os)) {
  207. osVersion = /Windows (.*)/.exec(os)[1];
  208. os = 'Windows';
  209. }
  210.  
  211. switch (os) {
  212. case 'Mac OS':
  213. case 'Mac OS X':
  214. case 'Android':
  215. osVersion = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([\.\_\d]+)/.exec(nAgt)[1];
  216. break;
  217.  
  218. case 'iOS':
  219. osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
  220. osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
  221. break;
  222. }
  223.  
  224. // flash (you'll need to include swfobject)
  225. /* script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" */
  226. var flashVersion = 'no check';
  227. if (typeof swfobject != 'undefined') {
  228. var fv = swfobject.getFlashPlayerVersion();
  229. if (fv.major > 0) {
  230. flashVersion = fv.major + '.' + fv.minor + ' r' + fv.release;
  231. }
  232. else {
  233. flashVersion = unknown;
  234. }
  235. }
  236. }
  237.  
  238. return {
  239. screen: screenSize,
  240. browser: browser,
  241. browserVersion: version,
  242. browserMajorVersion: majorVersion,
  243. mobile: mobile,
  244. os: os,
  245. osVersion: osVersion,
  246. cookies: cookieEnabled,
  247. flashVersion: flashVersion,
  248. isIntelX64: isIntelX64()
  249. };
  250. }
  251.  
  252. /*
  253. alert(
  254. 'OS: ' + jscd.os +' '+ jscd.osVersion + '\n' +
  255. 'Browser: ' + jscd.browser +' '+ jscd.browserMajorVersion +
  256. ' (' + jscd.browserVersion + ')\n' +
  257. 'Mobile: ' + jscd.mobile + '\n' +
  258. 'Flash: ' + jscd.flashVersion + '\n' +
  259. 'Cookies: ' + jscd.cookies + '\n' +
  260. 'Screen Size: ' + jscd.screen + '\n\n' +
  261. 'Full User Agent: ' + navigator.userAgent
  262. );*/
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. function nearestParent(dom, f){
  271.  
  272. let p = dom;
  273. while(p && p.nodeType>0){
  274. if(f(p)) return p
  275. p=p.parentNode;
  276. }
  277. return null;
  278.  
  279. }
  280.  
  281. function nOfType(elm){
  282. if(!elm)return -1;
  283. let parent = elm.parentNode;
  284. let i=0;
  285. if(!parent) return -1;
  286. for(const s of parent.children){
  287. if(elm===s) return i;
  288. if(s.nodeName==elm.nodeName) i++;
  289. }
  290. return -1;
  291.  
  292. }
  293.  
  294. let jscd=null;
  295.  
  296.  
  297. let addedStyle=null;
  298.  
  299.  
  300.  
  301. let m11=1;
  302. setInterval(function(){
  303. let e11;
  304. if(m11&&(e11=document.querySelector('td>a[id*="product"]:only-of-type>span:only-of-type'))){
  305.  
  306. m11=0;
  307.  
  308.  
  309. let e22=document.querySelector('td>a[id*="title"]:only-of-type>span:only-of-type');
  310.  
  311. if(!e22)return;
  312.  
  313. jscd = jscd||getJSCD();
  314.  
  315. let osVersion = jscd.os +' '+ jscd.osVersion;
  316. if(osVersion=='Windows 7'){
  317.  
  318. }
  319.  
  320.  
  321.  
  322. let tContainer = nearestParent(e11, (elm)=>elm.nodeName=="TBODY"||elm.nodeName=="TABLE");
  323.  
  324. let idx11=nOfType(nearestParent(e11, (elm)=>elm.nodeName=="TD"))
  325. let idx22=nOfType(nearestParent(e22, (elm)=>elm.nodeName=="TD"))
  326.  
  327.  
  328.  
  329.  
  330. let tds = tContainer.querySelectorAll(`td:nth-of-type(${idx11+1})`)
  331.  
  332. for(const elm of tds){
  333.  
  334. let products_txt = elm.textContent.replace(/[^a-zA-Z0-9\-\_\s\,]/g,'').trim();
  335. let products = products_txt.split(/\s*,\s*/);
  336. let isProductFound = products.includes(osVersion);
  337. /*
  338. Windows 7,Windows 8,Windows Server 2003,Windows Server 2003, Datacenter Edition,Windows Server 2008,Windows Server 2008 R2,Windows Server 2012,Windows Vista,Windows XP x64 Edition
  339. */
  340.  
  341. if(isProductFound){
  342.  
  343. let tr = nearestParent(elm, (elm)=>elm.nodeName=="TR")
  344.  
  345.  
  346. let title = tr.querySelector(`td:nth-of-type(${idx22+1})`)
  347.  
  348. let p = (title.textContent+'').match(/\b(x64|x86)\b/);
  349.  
  350. //console.log(p);
  351.  
  352. if(p){
  353. if((p[0]=='x86'&&jscd.isIntelX64===true)||(p[0]=='x64'&&jscd.isIntelX64===false)) continue;
  354. }
  355.  
  356. addedStyle=addedStyle||addStyle(cssText);
  357.  
  358. tr.setAttribute('ms-update-highlighted-row','')
  359.  
  360.  
  361. }
  362.  
  363. }
  364.  
  365. }
  366.  
  367. },250)
  368.  
  369.  
  370.  
  371.  
  372.  
  373. // Your code here...
  374. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址