自己写的油猴脚本 —— 贝壳网自动计算实际使用面积

最近在看房,准备冲一波。逛贝壳网的时候发现只展示了标注面积。由于有「公摊」这个东西的存在,导致我们房子到手后和标注的面积不一样。为了在贝壳上看房的时候有一个好的体验,能更快的获取到房子的实际使用面积,我写了这么个脚本。

实现效果

自己写的油猴脚本 —— 贝壳网自动计算实际使用面积

使用页面上提供的信息计算实际使用面积和得房率,让公摊无处可逃。

这个数据是使用页面下方的每个房间的面积加起来(如下图)算的。如果这个页面上没有这部分信息,那么就算不出来。

自己写的油猴脚本 —— 贝壳网自动计算实际使用面积

至于油猴怎么用,就不用我讲了吧~不知道油猴的话,把代码全部复制到浏览器控制台运行也是可以的。

最后是全部的代码。

// ==UserScript==
// @name         贝壳网自动计算实际使用面积
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       xt
// @match        https://*.ke.com/*
// @icon         https://www.google.com/s2/favicons?domain=ke.com
// @grant        none
// ==/UserScript==

(function() {
    // 计算实际使用面积
    var sum = 0;
    var d = document.getElementById('infoList').getElementsByClassName('row')
    var rows = []
    for (var i in d) (
        rows.push(d[i])
    )
    rows.map(v => {
        if (typeof v == 'object') {
            sum += (v.getElementsByClassName('col')[1].innerText.replace('平米', '') - 0)
        }
    })

    // 获取标注面积
    var vituralS = document.getElementsByClassName('mainInfo')[2].innerText.replace('平米', '') - 0

    var C = document.createElement('div')
    C.classList.add('area')
    var C1 = document.createElement('div')
    C1.classList.add('mainInfo')
    C1.innerText = `${Math.round(sum)} (${sum}) 平米`
    C1.style.color = 'red'
    C1.style.fontSize = '15px'
    var C2 = document.createElement('div')
    C2.classList.add('subInfo')
    C2.innerText = `实际使用面积`
    C2.style.color = 'red'
    C.append(C1)
    C.append(C2)
    var CC = document.createElement('div')
    CC.classList.add('area')
    var C3 = document.createElement('div')
    C3.classList.add('mainInfo')
    C3.innerText = `${Math.round(sum / vituralS * 100)}%`
    C3.style.color = 'red'
    var C4 = document.createElement('div')
    C4.classList.add('subInfo')
    C4.innerText = `得房率`
    C4.style.color = 'red'
    CC.append(C3)
    CC.append(C4)
    C.style.marginTop = '20px'
    CC.style.marginTop = '20px'
    document.getElementsByClassName('houseInfo')[0].append(C)
    document.getElementsByClassName('houseInfo')[0].append(CC)
    // Your code here...
})();
本作品采用《CC 协议》,转载必须注明作者和本文链接
从前从前,有个人爱你很久
thebestxt
讨论数量: 1
Summer

真是为了买房费尽心思哈 :smile: :smile: :smile:

2年前 评论
thebestxt (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!