omgtu-auto-schedule

Автоматически загружает последнее открытое расписание на сайте www.omgtu.ru

As of 2017-01-18. See the latest version.

// ==UserScript==
// @name omgtu-auto-schedule
// @description Автоматически загружает последнее открытое расписание на сайте www.omgtu.ru
// @author Савкин Владимир
// @license MIT
// @version 2.1.1
// @include http://www.omgtu.ru/students/temp*/
// @include http://omgtu.ru/students/temp*/
// @namespace https://greasyforks.org/users/64313
// ==/UserScript==

(function (window, undefined) {
    var w;
    if (typeof unsafeWindow !== undefined) {
        w = unsafeWindow;
    } else {
        w = window;
    }

    if (w.self != w.top) {
        return;
    }

    if (/http:\/\/www.omgtu.ru\/students\/temp*/.test(w.location.href)) {
        if(localStorage.getItem('ScheduleData')) {
            //Загрузка предыдущего открытого расписания
            set_values();
            update_schedule($('#schedule').serialize());
        }
    }
    
    if (/http:\/\/omgtu.ru\/students\/temp*/.test(w.location.href)) {
        if(localStorage.getItem('ScheduleData')) {
            //Загрузка предыдущего открытого расписания
            set_values();
            update_schedule($('#schedule').serialize());
            
        }
    }
})(window);

//Сохранение значения поля 'Факультет'
$('#faculty_list').change(function(){
    localStorage.clear();
    localStorage.ScheduleData.facultyText =  $('#faculty_list option:selected').text();
    console.log("Сохранение выбраного факультета");
});

//Сохранение значения поля 'Курс'
$("input[name='filter[course]']").change(function(){
    localStorage.ScheduleData.course = $('input[name=filter[course]]:checked', '#schedule').val();
    console.log("Сохранение выбраного курса");
});

//Сохранение значения поля 'Группа'
$('#group_list').change(function(){
    localStorage.ScheduleData.groupText = $('#group_list option:selected').text();
    console.log("Сохранение выбранной группы");
});

//Загрузка расписания по нажатию на "ФАКУЛЬТЕТЫ И ГРУППЫ"
$('#skey_g').click(function (){
    if(localStorage.getItem('ScheduleData')) {
        var data = localStorage.ScheduleData;
        //Загрузка предыдущего открытого расписания
        set_values();
        update_schedule(data);
        
    }
 });

function update_schedule(data) {
    var url = $('#schedule').attr("action");
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        dataType: 'json',
        success: function(data) {
            if (data.success) {
                $('#weekpicker-container').show();
                $('#schedule-list').html($($.trim(data.html)).find("#schedule-list").html());
            }
        },
    });
}

function set_values()
{   localStorage.ScheduleData
    var facultyText =localStorage.ScheduleData.facultyText,
        course  = localStorage.ScheduleData.course,
        groupText   =localStorage.ScheduleData.groupText;
    var index_active_radio_button = course - 1;
   
    $("#faculty_list option").each(function() {
        if($(this).text() == facultyText)
            $(this).attr('selected', 'selected');  
    });
    
   $("input:radio[name=filter[course]]:nth("+ index_active_radio_button +")").attr('checked',true);
   
   $("#group_list option").each(function() {
        if($(this).text() == groupText)
            $(this).attr('selected', 'selected');            
    });
    
    console.log(facultyText);
    console.log(course);
    console.log(groupText);
   
}

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}


function getUrlParameter(sParam, url) {
    var sPageURL = url,
        sURLVariables = sPageURL.split('&'),
        sParameterName, i;
//ToDo: Придумать как по другому игнорировать повторяющиеся атрибуты
       for (i = sURLVariables.length - 1; i > 0; i--) {
         sParameterName = sURLVariables[i].split('=');

         if (sParameterName[0] == sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
}
长期地址
遇到问题?请前往 GitHub 提 Issues。