fix insert classical works

fix inserting works into tracklist when work has apostrophe in title

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         fix insert classical works
// @namespace    https://greasyfork.org/users/2653
// @version      0.2
// @description  fix inserting works into tracklist when work has apostrophe in title
// @author       thought_house
// @match        https://rateyourmusic.com/releases/ac*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var searchFrame = document.getElementById("shortcutsearchframe");

    searchFrame.onload = function() {

        var infoboxes = document.getElementById("shortcutsearchframe").contentDocument.getElementsByClassName("infobox");

        for (var i = 0; i < infoboxes.length; i++) {
            var infobox = infoboxes[i];
            var workTitle = infobox.getElementsByClassName('infobox_title')[0].innerHTML;

            if (workTitle.indexOf("'") >= 0) {
                if (infobox.getAttribute('class').indexOf('child') >= 0) {
                    workTitle = workTitle.replace(/^\d+\. /, '');
                }

                var onclickcode = infobox.children[0].children[0].getAttribute('onclick');
                onclickcode = onclickcode.replace(workTitle, workTitle.replace(/'/g, "\\'"));
                infobox.children[0].children[0].setAttribute('onclick', onclickcode);
            }
        }
    }
})();