Enhanced Ziroom

这个插件可以在列表页就显示房源的一些额外状态,比如是否可租,是否可月租。

  1. // ==UserScript==
  2. // @name Enhanced Ziroom
  3. // @name:en Enhanced Ziroom
  4. // @namespace https://github.com/catscarlet/enhanced_ziroom
  5. // @description 这个插件可以在列表页就显示房源的一些额外状态,比如是否可租,是否可月租。
  6. // @description:en This is a userscript for www.ziroom.com
  7. // @version 0.2.0
  8. // @author catscarlet
  9. // @license Apache License 2.0
  10. // @match *://*.ziroom.com/z/nl/*.html*
  11. // @require https://code.jquery.com/jquery-latest.js
  12. // @compatible chrome 支持
  13. // @run-at document-end
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. window.jQueryLatest = $.noConflict(true);
  18.  
  19. (function() {
  20. 'use strict';
  21. var $ = window.jQueryLatest;
  22.  
  23. $(function() {
  24. console.log('enhanced_ziroom loaded');
  25. getHouseList();
  26. });
  27.  
  28. function getHouseList() {
  29. var houselist = $('#houseList li');
  30. houselist.each(function(index) {
  31. var priceDetail = $(this).find('.priceDetail');
  32. var detailUrl = priceDetail.find('.more').find('a').attr('href');
  33. var detailId = url2id(detailUrl);
  34. if (detailId) {
  35. priceDetail.append('<strong id=' + detailId + '>检测中...</strong>');
  36. setTimeout(function() {
  37. getDetail(detailUrl, detailId);
  38. }, 500);
  39. }
  40. });
  41. };
  42.  
  43. function getDetail(detailUrl, detailId) {
  44. $.ajax({
  45. type: 'GET',
  46. url: detailUrl,
  47. dataType: 'html',
  48. async: true,
  49. success: function(msg, textStatus, jqXHR) {
  50. checkDetail(msg, detailId);
  51. },
  52. error: function(msg) {
  53. console.log(msg);
  54. },
  55. });
  56. }
  57.  
  58. function checkDetail(msg, detailId) {
  59. var regexp_status_avaliable = new RegExp(/\<a[^\/a].*class=\"btn view\".*\>(.*)\<\/a>/);
  60. var regexp_status_unavaliable = new RegExp(/\s\<a[^\/a].*class=\"btn view viewGray\".*\>(.*)\<\/a>/);
  61. var regexp_name = new RegExp(/\<div.*class=\"room_name\".*\>(.|\n)*\<h2\>((.|\n)*)\<\/h2\>/g);
  62. var regexp_monthly = new RegExp(/<ul class=\"detail_room\">(?:.|[\n])*?<span class=\"icons\">月<\/span>(?:.|[\n])*?<\/ul>/g);
  63.  
  64. var name = domtext2text(msg.match(regexp_name)[0]);
  65. var status;
  66. var status_value = false;
  67. var status_avaliable = msg.match(regexp_status_avaliable);
  68. var status_unavaliable = msg.match(regexp_status_unavaliable);
  69. var monthly_avaliable = msg.match(regexp_monthly);
  70.  
  71. var extra_data = {
  72. monthly_avaliable: false,
  73. };
  74.  
  75. if (status_avaliable) {
  76. status = domtext2text(status_avaliable[0]);
  77. status_value = true;
  78. } else {
  79. status = domtext2text(status_unavaliable[0]);
  80. status_value = false;
  81. }
  82.  
  83. if (monthly_avaliable) {
  84. extra_data.monthly_avaliable = true;
  85. }
  86.  
  87. drawList(status_value, status, detailId, extra_data);
  88. }
  89.  
  90. function drawList(status_value, status, detailId, extra_data) {
  91. var css;
  92. var thedom = $('#' + detailId);
  93. if (status_value) {
  94. thedom.text(status);
  95. //thedom.parent().parent().css('background-color', 'lightgreen');
  96. } else {
  97. thedom.text(status);
  98. thedom.parent().parent().css('background-color', 'grey');
  99. }
  100.  
  101. if (extra_data.monthly_avaliable) {
  102. let monthly_style = 'width: 20px; height: 20px; background: #ffa000; border-radius: 5px; color: #fff; text-align: center; line-height: 20px; font-size: 14px; display: inline-block; margin-left: 10px;';
  103. let monthly_str = '<span style="' + monthly_style + '">月</span>';
  104. thedom.append(monthly_str);
  105. }
  106. }
  107.  
  108. function domtext2text(domtext) {
  109. var rst;
  110. rst = $.trim($.text($.parseHTML(domtext)));
  111.  
  112. return rst;
  113. }
  114.  
  115. function url2id(url) {
  116. var regexp_url2id = new RegExp(/\/(\d+)\.html/);
  117. var rst = url.match(regexp_url2id);
  118. if (rst) {
  119. return rst[1];
  120. }
  121.  
  122. return false;
  123. }
  124. })();

QingJ © 2025

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