PTH Request notes

Store notes on requests at PTH

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         PTH Request notes
// @version      0.2
// @description  Store notes on requests at PTH
// @author       Chameleon
// @include      http*://*redacted.ch/requests.php*
// @include      http*://*passthepopcorn.me/requests.php*
// @grant        none
// @namespace https://greasyfork.org/users/87476
// ==/UserScript==

(function() {
  'use strict';

  var before=document.getElementById('request_comments');
  if(!before)
    before=document.getElementById('comments');
  if(!before)
    return;
  
  var requestId=parseInt(window.location.href.split('id=')[1]);
  var comment=getComment(requestId);
  var div=document.createElement('div');
  before.parentNode.insertBefore(div, before);
  div.setAttribute('class', 'box box2');
  div.innerHTML='<div class="head"><strong>Notes</strong></div>';
  var pad=document.createElement('div');
  pad.setAttribute('class', 'pad');
  div.appendChild(pad);
  var t=document.createElement('textarea');
  t.setAttribute('id', 'requestNotes');
  t.setAttribute('style', 'width: 100%;');
  t.rows="8";
  pad.appendChild(t);
  t.value=comment;
  t.addEventListener('keyup', save.bind(undefined, requestId, t), false);
  resize('requestNotes');
})();

function save(id, t)
{
  var notes=window.localStorage.requestNotes;
  if(!notes)
    notes=[];
  else
    notes=JSON.parse(notes);
  
  var noteExisted=false;
  for(var i=0; i<notes.length; i++)
  {
    if(notes[i].id === id)
    {
      notes[i].comment=t.value;
      noteExisted=true;
      break;
    }
  }
  if(!noteExisted)
  {
    notes.push({id:id, comment:t.value});
  }
  
  window.localStorage.requestNotes=JSON.stringify(notes);
  resize('requestNotes');
}

function getComment(id)
{
  var notes=window.localStorage.requestNotes;
  if(!notes)
    notes=[];
  else
    notes=JSON.parse(notes);
  
  for(var i=0; i<notes.length; i++)
  {
    if(notes[i].id === id)
      return notes[i].comment;
  }
  
  return '';
}