LoginSignup
0
0

More than 5 years have passed since last update.

RecentChangesを見易くする?Userscriptを書いた

Posted at

はじめに

自分の職場では、情報共有や日誌としてPukiWikiがまだまだ頑張っている。
更新チェックにRecentChangesのページをよく開くが、前回どこまで見たのかピンとこないことがあるので、前回RecentChangesを開いてから更新がないページを目立たなくするUserscriptを書いてみた。

スクリプト

highlightupdated.user.js
// ==UserScript==
// @name        HighlightRecentChanges
// @namespace   http://horihiro.net/
// @include     http://SERVER_NAME/index.php?RecentChanges
// @version     1
// @grant       none
// ==/UserScript==

(function(){
  var lastAccess = localStorage.lastAccess;
  // 前回開いた日時があるかチェック
  if (lastAccess && !isNaN(lastAccess)) {
    try {
      lastAccess = new Date(parseInt(lastAccess));
      Array.prototype.forEach.call(document.querySelectorAll(".list1>li"),  function(li){
        // 各項目の更新日時を取得
        var updated = new Date(li.innerText.replace(/(\d{4}-\d{2}-\d{2}).*(\d{2}:\d{2}:\d{2}).*$/,'$1 $2'));
        // 前回開いた日時と比較
        if (updated.getTime() < lastAccess.getTime()) {
          // 前回開いた日時よりも更新時間が古ければ薄くする
          li.style.color = 'lightgray';
        }
      });
    } catch(ex) {
      console.log(ex);
    }
  };
  // 現在日時をlocalStorageに保存
  localStorage.lastAccess = Date.now();  
})();

ヘッダーのSERVER_NAMEはPukiWikiのサーバ名に置き換える。

注意

localStorageにアクセス日時を保存して、それと各ページの更新日時を比較してる。
なので、PCを変えるのはもちろん、同じPCでもブラウザを変えたら、既に見たページも薄くならない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0