FlandreDaisuki / Patchouli

An image searching and browsing tool on pixiv
MIT License
80 stars 6 forks source link

Ugoira autoplay can't work on Greasemonkey #22

Open FlandreDaisuki opened 6 years ago

FlandreDaisuki commented 6 years ago

Describe the bug

As title

Steps to reproduce

  1. Go to search うごイラ
  2. Let mouse hover image

Screenshots

No

Environment

Debug messages

No error message... G_G

``` Paste here. 貼在這裡。 ```
maple3142 commented 6 years ago

想問一下要怎麼測試這個... 因為我發現 greasymonkey 完全無法使用: image

FlandreDaisuki commented 6 years ago

記得把其他腳本管理器停用 到 dist/patchouli.dev.user.js 頁面點 Raw 應該就能安裝了

maple3142 commented 6 years ago

已經把 FF 的 TM 停用了,不過好像每個腳本都安裝不了 感覺是 GM 的 bug...

FlandreDaisuki commented 6 years ago

我可以耶 Windows 10 Firefox 62.0b8 (64bit) GM 4.6 default

maple3142 commented 6 years ago

我是在按下 安裝 後會出現那個 undefined 的 error

yanagiragi commented 6 years ago

Windows 10 Firefox 61.0.1 (64bit) GM 4.6

可以作用喔

default

maple3142 commented 6 years ago

這是我看到的 == 不只 Patchouli 會這樣,任何腳本都有這個問題 gif

maple3142 commented 6 years ago

在重設 FF 之後就能使用了 然後透過一些蠻怪異的方法想辦法強制去繞過 GM 的奇怪限制... 效果 主要修改的地方是這段: https://gist.github.com/maple3142/9d3ad92c6cfb4bbde42470252842146d#file-patchouli-gmcompatible-user-js-L1171-L1294

話說我覺得 GM 真的和 TM,VM 很不一樣,尤其是 unsafeWindow 方面... 我如果遇到這種問題我應該會想直接放棄支援 GM

FlandreDaisuki commented 6 years ago

我之前就有發現... GM 的 sandbox 包到連 debug 都很難搞

那就先放著吧,如果有人有這個疑問可以來 ref 這個 issue Orz

maple3142 commented 6 years ago

不知道這能不能當作 bug 去回報給 greasemonkey,看他們說是 bug 還是 works as expected

不過它們的沙盒程度真的很誇張...,想用 unsafeWindow.xxx=obj 然後在 console 測試也不行

maple3142 commented 6 years ago

有個比較簡單的方法可以支援 GM(如果需要的話),就是直接把整個 script 塞到頁面中執行...

;(function() {
    'use strict'
    const loadScript = ({ src, code, timeout = 3000 }) =>
        new Promise((res, rej) => {
            const s = document.createElement('script')
            if (src) s.src = src
            else if (code) s.textContent = code
            else throw new Error('Either src or code must provided!')
            s.onload = () => {
                s.remove()
                res()
            }
            s.onerror = () => {
                s.remove()
                rej()
            }
            setTimeout(() => {
                s.remove()
                res()
            }, timeout)
            document.body.appendChild(s)
        })
    const scripts = [
        'https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js',
        'https://cdnjs.cloudflare.com/ajax/libs/vuex/3.0.1/vuex.min.js',
        'https://cdnjs.cloudflare.com/ajax/libs/vue-i18n/7.8.0/vue-i18n.min.js',
        'https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js',
        'https://cdn.rawgit.com/FlandreDaisuki/zip_player/ecf3751317079fcabef70af4bd0e92411288303d/dist/zip_player.iife.min.js'
    ]
    const code = `${main.toString()}
    window.GM_info=${JSON.stringify(GM_info)}
    window.unsafeWindow=window
    main(Vue,Vuex,VueI18n)
    delete window.GM_info
    delete window.unsafeWindow`
    scripts.reduce((p, src) => p.then(() => loadScript({ src })), Promise.resolve()).then(() => loadScript({ code }))
})()
function main(Vue, Vuex, VueI18n) {
    // actual code
}
FlandreDaisuki commented 6 years ago

我就是不想動態插 script 才搞這麼複雜的 Orz 反正目前找出找出問題的也只有我自己,等真的有需求再說 也說不定之後有需求的時候 GM 就莫名可以用了