51job search filter with distance

51job搜索结果以距离过滤

目前为 2019-11-24 提交的版本。查看 最新版本

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

QingJ © 2025

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