GSMArena Highlight Compare Differences

See https://greasyfork.org/forum/discussion/449/gsmarena-com-a-script-to-highlight-rows-with-differences-when-comparing-phones

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        GSMArena Highlight Compare Differences
// @author      Jefferson "jscher2000" Scher
// @namespace   JeffersonScher
// @description See https://greasyfork.org/forum/discussion/449/gsmarena-com-a-script-to-highlight-rows-with-differences-when-comparing-phones
// @license     BSD 3-clause
// @include     http://www.gsmarena.com/compare.php3*
// @version     0.1.1
// @grant       none
// ==/UserScript==

// Only run if a second phone was selected (check for presence of nfo2 entries)
var test = document.getElementsByClassName("nfo2");
if (test.length > 0){
  // Add rules to style rows designated as having differences
  var s = document.createElement("style");
  s.setAttribute("type", "text/css");
  s.appendChild(document.createTextNode(".hcdiff .ttl, .hcdiff .nfo, .hcdiff .nfo2{background:#ffb !important; box-shadow:inset 0 0 .45em #ee0 !important;}"));
  document.body.appendChild(s);
  // Check all rows under #specs-list (there are numerous tables in here)
  var rows = document.querySelectorAll("#specs-list tr");
  for (var i=0; i<rows.length; i++){
    if (rows[i].children.length > 1){
      // Compare the last cell in the row to the send-to-last (needed because numbers of cells can vary)
      if (rows[i].lastElementChild.innerHTML != rows[i].lastElementChild.previousElementSibling.innerHTML){
        rows[i].className = "hcdiff";
      }
    }
  }
}