NYT Temperature Conversion

Converts weather temperature from the NYT website from Fahrenheit to Celsius

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NYT Temperature Conversion
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Converts weather temperature from the NYT website from Fahrenheit to Celsius
// @author       Rodrigo García
// @match        http://international.nytimes.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require      https://greasyfork.org/scripts/1003-wait-for-key-elements/code/Wait%20for%20key%20elements.js?version=49342
// @grant        none
// @run-at       document-idle
// ==/UserScript==
/* jshint -W097 */
'use strict';

waitForKeyElements(".weather-button", convertTemperature);

function convertTemperature(jNode) {
    var weatherButton       = document.getElementsByClassName('weather-button')[0];
    var fahrenheitString    = weatherButton.textContent.trim();
    var fahrenheit          = fahrenheitString.substr(0,fahrenheitString.length-2);
    var celsius             = Math.round((parseFloat(fahrenheit)-32)*5/9);
    var celsiusString       = celsius.toString()+'°C'; 
    weatherButton.innerHTML = weatherButton.innerHTML.replace(fahrenheitString,celsiusString);
}