holatuwol / Show NovelUpdates Private Ratings

// ==UserScript==
// @name           Show NovelUpdates Private Ratings
// @namespace      holatuwol
// @license        0BSD
// @version        0.3
// @include        https://www.novelupdates.com/reading-list/*
// @grant          none
// ==/UserScript==

var styleElement = document.createElement('style');

styleElement.textContent = `
.nu_editnotes {
  display: none;
}

.l-subheader-h, .l-submain-h, .l-subfooter-h {
  max-width: 100%;
}

table.tablesorter thead tr th.private-rating,
table.tablesorter tbody tr td.private-rating {
  text-align: center;
}
`;

document.head.appendChild(styleElement);

function addRatingHeader() {
  var header = document.querySelector('.tablesorter thead tr');

  var cell = document.createElement('th');
  cell.classList.add('header');
  cell.classList.add('read');
  cell.classList.add('private-rating');

  cell.textContent = '❤️';

  header.appendChild(cell);
}

function addRating(row) {
  var cell = document.createElement('td');
  cell.classList.add('private-rating');
  
  if (row.cells.length == 4) {
    row.cells[0].width = '5%';
    row.cells[1].width = '50%';
    row.cells[2].width = '20%';
    row.cells[3].width = '20%';
    cell.width = '5%';
  }
  else {
    row.cells[0].width = '10%';
    row.cells[1].width = '80%';

    cell.width = '10%';
  }
  
  cell.textContent = row.getAttribute('data-rate') || '--';
  row.appendChild(cell);
}

addRatingHeader();

var rows = document.querySelectorAll('.tablesorter tbody tr');

for (var i = 0; i < rows.length; i++) {
    addRating(rows[i]);
}