Greasy Fork

来自缓存

Greasy Fork is available in English.

链家租房列表增加一些信息

比如加上小区的建筑年代

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         链家租房列表增加一些信息
// @namespace    http://greasyfork.icu/zh-CN/users/177458-bd777
// @version      0.2
// @description  比如加上小区的建筑年代
// @author       windeng
// @match        https://gz.lianjia.com/zufang/*
// @icon         https://www.google.com/s2/favicons?domain=lianjia.com
// @require      http://greasyfork.icu/scripts/433586-simpletools/code/SimpleTools.js?version=977251
// @grant        GM_xmlhttpRequest
// ==/UserScript==

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver

async function GetXiaoquPage(xiaoquId) {
  return Get(`https://gz.lianjia.com/xiaoqu/${xiaoquId}`)
}

async function GetXiaoquInfo(xiaoquId) {
  let resp = await GetXiaoquPage(xiaoquId)
  // console.log(resp)
  let el = document.createElement('html')
  el.innerHTML = resp
  // console.log(el)
  let elemList = el.querySelectorAll('div.xiaoquInfo > div.xiaoquInfoItem')
  let result = {}
  for (let i = 0; i < elemList.length; ++i) {
    let elem = elemList[i]
    let label = elem.querySelector('span.xiaoquInfoLabel').innerText.trim()
    let content = elem.querySelector('span.xiaoquInfoContent').innerText.trim()
    result[label] = content
  }

  return result
}

async function DoLogic() {
  await WaitUntil(() => {
    return !!document.querySelector('div.content__list')
  })

  let divList = document.querySelectorAll('div.content__list--item')
  for (let i = 0; i < divList.length; ++i) {
    let div = divList[i]
    // 获取小区id
    let a = div.querySelector('p.content__list--item--des > a:nth-of-type(3)')
    let matches = a.getAttribute('href').match(/zufang\/c(\d+)/)
    // console.log(a, matches)
    if (!matches) continue
    let xiaoquId = matches[1]

    // 增加跳转到小区的按钮
    let tmpA = document.createElement('a')
    tmpA.setAttribute('href', `/xiaoqu/${xiaoquId}`)
    tmpA.setAttribute('target', '_blank')
    tmpA.innerText = '小区主页'
    a.parentNode.insertBefore(tmpA, a.nextSibling)
    let tmpSpan = document.createElement('span')
    tmpSpan.innerText = '-'
    a.parentNode.insertBefore(tmpSpan, tmpA)

    let xiaoquInfo = await GetXiaoquInfo(xiaoquId)
    console.log(xiaoquInfo)
    let desElem = div.querySelector('p.content__list--item--des')
    let span = document.createElement('span')
    span.innerHTML = `<i>/</i> ${xiaoquInfo["建筑年代"]}`
    desElem.appendChild(span)

    /*
    GetXiaoquInfo(xiaoquId).then(xiaoquInfo => {
        console.log(xiaoquInfo)
        let desElem = div.querySelector('p.content__list--item--des')
        let span = document.createElement('span')
        span.innerHTML = `<i>/</i> ${xiaoquInfo["建筑年代"]}`
        desElem.appendChild(span)
    }).catch(err => {
        console.error(err)
    })
    */
  }
}

(async function () {
  'use strict';

  // Your code here...
  await DoLogic()
})();