RedFinPlus

Provide an external links for title reviews

目前為 2018-09-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         RedFinPlus
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Provide an external links for title reviews
// @author       [email protected]
// @match        http*://www.redfin.com/*
// @include      /^https?:\/\/www.redfin.com\/.*\/[\d]+$/
// @grant        GM_*
// @grant        unsafeWindow
// @run-at       document-end
// @require      http://code.jquery.com/jquery-3.2.1.min.js

// ==/UserScript==
// devtools.chrome.enabled: true
// devtools.debugger.remote-enabled: true
var timer;

var GetAddressParts = function(address_url) {
    var myRegx = /http[s]?:\/\/www.redfin.com\/([\w]+)\/([\w]+)\/([\w-+]+)-([\d]+)?(\/(.*))?\/home\/([\d]+)/ig
    var res = myRegx.exec(address_url);
    return {
        "state":res[1],
        "city":res[2],
        "display":res[3],
        "zip":res[4],
        "unit":res[6],
        "propertyId":res[7],
    };
};

function replaceAll(original_str, find_str, replace_str) {
  return original_str.split(find_str).join(replace_str);
};

var HandleHouse = function() {
    //debugger;
    console.log("detected a house url");
    var commentsSection = jQuery("[class*='CommentsSection']")[0];
    console.log("commentsSection = " + commentsSection.attributes[0].value);
    var parent = commentsSection.parentNode;

    var address_parts = GetAddressParts(location.href)
    //console.log("address_parts = " + address_parts);

    var areavibes_sub_path = ""
    if (address_parts.display.length > 0) {
        areavibes_sub_path = address_parts.city + "-" + address_parts.state + "/livability/";
    }
    var areavibes = document.createElement("DIV")
    areavibes.innerHTML = "<H2>Areavibes</H2><IFRAME width='100%' height='500' src='https://www.areavibes.com/" + areavibes_sub_path + "'/>"
    parent.appendChild(areavibes);

    var spotcrime_sub_path = ""
    if (address_parts.display.length > 0) {
        spotcrime_sub_path = "#"
            + replaceAll(address_parts.display, '-', '%20') + "%2C"
            + replaceAll(address_parts.city, '-', '%20') + "%2C"
            + address_parts.state + '%20' + address_parts.zip;
    }
    var spotcrime = document.createElement("DIV")
    spotcrime.innerHTML = "<H2>spotcrime</H2><IFRAME width='100%' height='500' src='https://spotcrime.com/"+spotcrime_sub_path+"'/>"
    parent.appendChild(spotcrime);

    var my_score = document.createElement("DIV");
    // Since my local server is http, it can't load inside the https://redfin without security exception
    // please turn on the "load dangerous script" see: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/8QvDA6p3YoI
    my_score.innerHTML = "<H2>My Score</H2><IFRAME width='100%' height='500' src='http://localhost:8000/SearchByURL" + location.pathname+"'/>";

    parent.appendChild(my_score);
};

(function() {
    'use strict';

    // check URL to see if it represents a house
    //debugger;
    if (/^https?:\/\/www.redfin.com\/.*\/[\d]+$/.test (location.href) ) {
        timer = setTimeout(HandleHouse, 5000);
    }
})();