Sankaku Channel NoteFix

Fix notes for dark userstyle

// ==UserScript==
// @name        Sankaku Channel NoteFix
// @namespace   Galinoa
// @description Fix notes for dark userstyle
// @match       *://chan.sankakucomplex.com/post/show/*
// @version     1.2.3
// @grant       none
// @icon        https://images.sankakucomplex.com/gfx/favicon.png
// ==/UserScript==

var image = document.getElementById('image');
var noteCon = document.getElementById('note-container');

// Notes placement
function fixNote() {
  var ncml = (window.innerWidth - image.clientWidth) / 2;
  noteCon.style.marginLeft = (ncml + 'px');
}

// Only fix notes when note boxes are present
if (document.getElementsByTagName('html')[0].innerHTML.indexOf('class="note-box"') > 0) {
  
  // Check if image is resized, then adds the note placement and makes sure it stays put.
  if (image.getAttribute('width') <= window.innerWidth && image.getAttribute('orig_width')) {
    fixNote();
    window.addEventListener('resize', fixNote, false);
  }

  // When image is clicked, makes sure the notes are placed correctly on the resized image.
  document.getElementById('image-link').onclick = function() {
    if (image.getAttribute('width') >= window.innerWidth) {
  	  noteCon.style.marginLeft = (0 + 'px');
      window.removeEventListener('resize', fixNote, false);
    } else {
      fixNote();
    }
  }; 
  
}