isares / Auto Checked EvaluateKU

// ==UserScript==
// @name         Auto Checked EvaluateKU
// @namespace    https://openuserjs.org/users/isares
// @version      0.1
// @description  For Lazy Person!
// @author       Isares
// @license MIT
// @copyright 2018, isares (https://openuserjs.org/users/isares)
// -----URL-----
// @match        https://eassess.ku.ac.th/m/source/assess_55_type1.php
// @match        https://eassess.ku.ac.th/m/source/assess_55_type2.php
// @match        https://eassess.ku.ac.th/AssessKU-V3/open_form.php
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var file = document.location.pathname;
    var length;
    var choiceID;
    var i;
    if (file.match("/m/source")){
        if (file == "/m/source/assess_55_type1.php"){
            length = 8;
        } else if (file == "/m/source/assess_55_type2.php"){
            length = 13;
        }

        for (i = 1; i <= length; i++){
            choiceID = "choice" + i + "-4"; //choice1-4
            document.getElementById(choiceID).checked = true;
        }
    } else if (file == "/AssessKU-V3/open_form.php"){
        length = 78;
        for (i = 1; i <= length; i++){
            choiceID = "a[" + i + "]-4"; //a[1]-4
            if (document.getElementById(choiceID)){
                document.getElementById(choiceID).checked = true;
            }
        }
    }
})();