Redirect to old osu! site

Redirects to osu! old site by simulating click event on site switcher button, and also updates site version cookie expiration date

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Redirect to old osu! site
// @description    Redirects to osu! old site by simulating click event on site switcher button, and also updates site version cookie expiration date
// @author         Devocub
// @copyright      2019, Devocub
// @version        0.1
// @icon           http://osu.ppy.sh/favicon.ico
// @include        http*://osu.ppy.sh/*
// @include        http*://new.ppy.sh/*
// @grant          none
// @namespace https://greasyfork.org/users/296854
// ==/UserScript==

// switcher code
// https://s.ppy.sh/js/site-switcher.js

Main();

function Main ()
{
    // update cookie
    document.cookie = 'osu_site_v=old; path=/; domain=.ppy.sh; max-age=9999999999999;';

    // new or old site ?
    // code from switcher
    var currentPage = document.location.pathname + document.location.search;
    var newSitePaths = /^\/(admin|beatmaps|beatmapsets|community|store|users|help|home|rankings|legal|mp|g|groups)/i;
    var newSite = newSitePaths.test(currentPage);

    // run click event only on new site
     if (newSite)
	{
		// switcher button element
		var switcherButton = document.getElementById('osu-site-switcher');

		// check button exists
		if (switcherButton !== null)
		{
			// log
			console.log("Redirect to old site: switching to old site\n");

			// simulate click
			eventFire(switcherButton, 'click');
		}

    }

}

// Simulate event function
function eventFire(el, etype){
  if (el.fireEvent) {
    el.fireEvent('on' + etype);
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}