51job search filter with distance

51job搜索结果以距离过滤

目前為 2020-02-06 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name:zh-CN 51job search filter with distance
  3. // @name 51job search filter with distance
  4. // @namespace https://github.com/zhuzemin
  5. // @description 51job搜索结果以距离过滤
  6. // @description:zh-CN 51job搜索结果以距离过滤
  7. // @author zhuzemin
  8. // @include https://search.51job.com/list/*
  9. // @version 1.2
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_addStyle
  15. // @connect-src api.map.baidu.com
  16. // @connect-src search.51job.com
  17. // ==/UserScript==
  18.  
  19. /*
  20. Setting "Home point" & "Distance limit":
  21. Coordinate from Baidu map: https://api.map.baidu.com/lbsapi/getpoint/index.html
  22. */
  23. "use strict";
  24. // setting User Preferences
  25. function setUserPref(varName, defaultVal, menuText, promtText, sep){
  26. GM_registerMenuCommand(menuText, function() {
  27. var val = prompt(promtText, GM_getValue(varName, defaultVal));
  28. if (val === null) { return; } // end execution if clicked CANCEL
  29. // prepare string of variables separated by the separator
  30. if (sep && val){
  31. var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g'); // trim space/s around separator & trim repeated separator
  32. var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
  33. //val = val.replace(pat1, sep).replace(pat2, '');
  34. }
  35. //val = val.replace(/\s{2,}/g, ' ').trim(); // remove multiple spaces and trim
  36. GM_setValue(varName, val);
  37. // Apply changes (immediately if there are no existing highlights, or upon reload to clear the old ones)
  38. //if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
  39. //else location.reload();
  40. });
  41. }
  42. // prepare UserPrefs
  43. setUserPref(
  44. 'homepoint',
  45. '0',
  46. 'Set Home point',
  47. `Set "home point" with "Baidu Map" point". Example: "39.122174, 117.215491"`,
  48. ','
  49. );
  50. setUserPref(
  51. 'distance',
  52. '6000',
  53. 'Set Distance',
  54. 'Set the distance for how far from home.'
  55. );
  56.  
  57. var cssContent= `
  58. .dw_table .t3{
  59. width:200px
  60. }
  61. `
  62. GM_addStyle(cssContent);
  63. const ORIGINP=GM_getValue("homepoint");
  64. const LIMIT=GM_getValue("distance");
  65. class Job51{
  66. constructor(jobid){
  67. this.url='https://search.51job.com/jobsearch/bmap/map.php?jobid='+jobid;
  68. this.jobid=jobid;
  69. this.charset='text/plain;charset=gbk';
  70. }
  71. }
  72. class Baidu{
  73. constructor(originP,lat,lng){
  74. this.ak="RGBBNuGoAcxvzl02ibOAxGZM";
  75. this.url=`https://api.map.baidu.com/direction/v2/riding?origin=${originP}&destination=${lat},${lng}&ak=${this.ak}`;
  76. this.charset='text/plain;charset=utf8';
  77. }
  78. }
  79. var resultList=document.querySelector("#resultList");
  80. var divs=resultList.querySelectorAll("div.el");
  81. for (var i = 1; i < divs.length; ++i){
  82. (function(div){
  83. var jobid=div.querySelector("input.checkbox").getAttribute("value");
  84. //console.log(riding);
  85. let job51=new Job51(jobid);
  86. GM_xmlhttpRequest({
  87. method: 'GET',
  88. url: job51.url,
  89. headers: {
  90. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  91. 'Accept': 'application/atom+xml,application/xml,text/xml',
  92. 'Referer': 'https://search.51job.com/jobsearch/bmap/map.php?jobid=102801929',
  93. },
  94. overrideMimeType:job51.charset,
  95. //synchronous: true
  96. onload: function(responseDetails) {
  97. var a=detail_addr( responseDetails,div);
  98. var lat=a[0];
  99. var lng=a[1];
  100. // console.log(lat);
  101. if(ORIGINP!="0"||ORIGINP!=""){
  102. (function(){
  103. let baidu=new Baidu(ORIGINP,lat,lng);
  104. GM_xmlhttpRequest({
  105. method: 'GET',
  106. url: baidu.url,
  107. headers: {
  108. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  109. 'Accept': 'application/atom+xml,application/xml,text/xml',
  110. 'Referer': 'https://search.51job.com/jobsearch/bmap/map.php?jobid=102801929',
  111. },
  112. overrideMimeType:baidu.charset,
  113. //synchronous: true
  114. onload: function(responseDetails) {
  115. try{
  116. filter( responseDetails,div,resultList);
  117. }
  118. catch(err){
  119. console.log(err);
  120. //continue;
  121. }
  122. }
  123. });
  124. })();
  125.  
  126. }
  127. }
  128. });
  129. })(divs[i]);
  130. }
  131. function detail_addr(ret,div){
  132. var g_company=JSON.parse(ret.responseText.match(/\{.*\}/)[0].replace(/([\'\"])?([a-zA-Z0-9_]+)([\'\"])?:/g, '"$2": '));
  133. var address=g_company.address;
  134. var lat=g_company.lat;
  135. var lng=g_company.lng;
  136. var region=div.querySelector("span.t3");
  137. //region.width="300px";
  138. region.textContent=address;
  139. return [lat,lng]
  140. }
  141. function filter(ret,div,resultList){
  142. let riding=JSON.parse(ret.responseText);
  143. // console.log(riding);
  144. let distance=parseInt(riding.result.routes[0].distance);
  145. //console.log(distance);
  146. if(distance>LIMIT&&distance<100000){
  147. resultList.removeChild(div);
  148. }
  149. }
  150. function createElementFromHTML(htmlString) {
  151. var div = document.createElement('div');
  152. div.innerHTML = htmlString.trim();
  153.  
  154. // Change this to div.childNodes to support multiple top-level nodes
  155. return div.firstChild;
  156. }
  157. function addGlobalStyle(css) {
  158. var head, style;
  159. head = document.getElementsByTagName('head')[0];
  160. if (!head) { return; }
  161. style = document.createElement('style');
  162. style.type = 'text/css';
  163. style.innerHTML = css;
  164. head.appendChild(style);
  165. }
  166.  

QingJ © 2025

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