Github PR review: mark moved files as viewed

Adds an option to the Github PR review page to mark moved files as viewed.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name     Github PR review: mark moved files as viewed
// @description  Adds an option to the Github PR review page to mark moved files as viewed.
// @include  https://github.com/*
// @license  GPLv2
// @version  1
// @grant    none
// @namespace https://greasyfork.org/users/13329
// ==/UserScript==

function should_mark(file) {
  if (file.dataset.fileDeleted === 'true') {
    return true;
  }
  
  const changes = file.getElementsByClassName('diffstat')[0].childNodes[0].textContent.trim();
  if (changes === '0' || changes === 'BIN') {
    return true;
  }
}

function mark_moved_files(event) {
  event.preventDefault();
  for (const file of document.getElementsByClassName('file')) {
    if (should_mark(file)) {
    	const checkbox = file.getElementsByClassName('js-reviewed-checkbox')[0];
    	if (!checkbox.checked) {
	      checkbox.click();
	    }
	  }
  }
  return false;
}


function add_checkbox(callback) {
  const submit_button = document.getElementById('whitespace-cb-lg')?.form?.elements?.[5];
  if (!submit_button) {
    return;
  }

  const button = document.createElement('button');
  button.addEventListener('click', callback);
  button.setAttribute('class', 'btn-sm btn');
  button.setAttribute('id', 'ignore-moved-files');

  button.append(document.createTextNode('Mark moved files as read'));

  submit_button.parentNode.insertBefore(button, submit_button);
}

function init() {
  add_checkbox(mark_moved_files);
}

window.addEventListener('DOMContentLoaded', init);