Greasy Fork is available in English.

y_method

ちょっとした機能

Version vom 10.01.2021. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/419955/889438/y_method.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         y_method
// @version      0.1
// @description  ちょっとした機能
// @author       y_kahou
// ==/UserScript==


/**
 * 対象までスクロールせずにクリックする
 * @param selector {string} - 取得対象のセレクタ
 */
function click_(element) {
    var x = window.scrollX, y = window.scrollY
    element.click()
    window.scrollTo(x, y)
}
/**
 * 対象までスクロールせずにフォーカスする
 * @param selector {string} - 取得対象のセレクタ
 */
function focus_(element) {
    var x = window.scrollX, y = window.scrollY
    element.focus()
    window.scrollTo(x, y)
}
/**
 * 対象のdomを取得できるまで取得を挑戦する
 * @param selector {string} - 取得対象のセレクタ
 * @param interval {number} - 次の挑戦までの時間ms
 * @param repeat   {number} - 繰り返し回数
 */
function repeatGetElements(selector, interval = 500, repeat = 60) {
    return new Promise(function(resolve, reject) {
        var cnt = 0
        var it = setInterval(function() {
            if (++cnt > 60) {
                clearInterval(it)
                reject("Could'n get " + selector)
            }
            var ret = document.querySelectorAll(selector)
            if (ret.length > 0) {
                clearInterval(it)
                resolve(ret)
            }
        }, interval)
    })
}
/**
 * async関数内で使えるwait
 */
function wait(ms = 100) {
    return new Promise(function(resolve, reject) {
        setTimeout(() => resolve(), ms)
    })
}


if (window.jQuery) (function($) {
    /**
     * 対象までスクロールせずにクリックする
     */
    $.fn.click_ = function() {
        click_(this[0])
        return this
    }
    /**
     * 対象までスクロールせずにフォーカスする
     */
    $.fn.focus_ = function() {
        focus_(this[0])
        return this
    }
})(window.jQuery);