shenruisi / Stay

Stay is a local userscript manager and an extension sample for Safari on iOS/iPadOS.
https://github.com/shenruisi/Stay/wiki
Mozilla Public License 2.0
1.11k stars 66 forks source link

[Script Migrate]: Adjust current monkey script to Stay #29

Open anc95 opened 2 years ago

anc95 commented 2 years ago

Hello, Thanks for your Stay enables script on ios and ipados safari

I have written a script to show online movie resource when user surf movie.douban.com. It works well on chrome and safari of pc(macOS). Now I want use it on my ipad. I created a new script on Stay and copied my code(monkey script) here added to Stay. I am ensure I enabled Stay extensions and gave all needed privilege. But it seems just not work.

  1. I noticed that Stay support debug on safari, Can you tell me how to do that. (I will be better if you can create some video demo to show these info)
  2. A common question, What do I special careful when move a monkey script to Stay script
shenruisi commented 2 years ago

@anc95 Did your script show the link list on the right side? It seems to work on my iPad simulator.

image
  1. Make sure you have successfully added the script, I check the script and find out you should remove @grant none (It is a bug on Stay 2.0.1).
  2. Make sure you have activated the script in your library list.
shenruisi commented 2 years ago

@anc95 If you finish testing your script ok on Stay², it should be great if you put the Stay² available signature on your Greasy fork homepage.

Stay
<img width="242px" src="https://raw.githubusercontent.com/shenruisi/Stay-Offical-Userscript/main/Stay-signature%403x.png" alt="Stay" />
anc95 commented 2 years ago

https://user-images.githubusercontent.com/13167934/150564960-76791a98-14ab-443d-935d-c44657c845bf.MOV

I captured a screenshot. I have activated my script and set Stay enabled for safari.

The weird thing is when I click Stay icon in url zone, just shows a shadowed icon under it, is it expected?

shenruisi commented 2 years ago

IMG_2979.MOV

I captured a screenshot. I have activated my script and set Stay enabled for safari.

The weird thing is when I click Stay icon in url zone, just shows a shadowed icon under it, is it expected?

A shadowed icon is an adapt problem on iPadOS(But this issue does not affect the script running). Could you like to give me an email address? I will invite you to TestFlight with the latest version.

anc95 commented 2 years ago

@shenruisi My email is 1481988258@qq.com, Thx. By the way, is there a method to debug script on ipad

shenruisi commented 2 years ago

@shenruisi My email is 1481988258@qq.com, Thx. By the way, is there a method to debug script on ipad

Invited. First, you need to check the console of the popup view if there is some exception on your script. And you can debug your script using GM_log to output the logs.

anc95 commented 2 years ago

@shenruisi I connected ipad to my Mac, and debug in develop tools I noticed you wrap my script content with gm_init, and I tried to modify script.content with my origin script content(without gm_init wrapped)before sendMessage of injectScript, it result in working well. (But if with gm_init wrapped, it not working, meanwhile without related error in console)

if (script.active){ //inject active script
    console.log("injectScript",script);
   // before this, I exec `script.content =${origin script}` in console
    browser.runtime.sendMessage({
        from: "bootstrap",
        operate: "injectScript",
        code:script.content,
        allFrames:!script.noFrames,
        runAt:"document_"+script.runAt
    });
}
shenruisi commented 2 years ago

@shenruisi I connected ipad to my Mac, and debug in develop tools I noticed you wrap my script content with gm_init, and I tried to modify script.content with my origin script content(without gm_init wrapped)before sendMessage of injectScript, it result in working well. (But if with gm_init wrapped, it not working, meanwhile without related error in console)

if (script.active){ //inject active script
    console.log("injectScript",script);
   // before this, I exec `script.content =${origin script}` in console
    browser.runtime.sendMessage({
        from: "bootstrap",
        operate: "injectScript",
        code:script.content,
        allFrames:!script.noFrames,
        runAt:"document_"+script.runAt
    });
}

gm_init just nested your script to an async function, so we can use await feature in our init function. But it just affects some code you want to do something on context loaded. By the. way, which branch did you test on? I run your script from the greasy fork homepage, it always runs ok on branch 2.0.2.

I have invited you to the internal testing of version 2.0.2, please check.

shenruisi commented 2 years ago

Any update? @anc95

anc95 commented 2 years ago

@shenruisi I am on CNY, I will try your solution tomorrow and then feedback here.

anc95 commented 2 years ago

@shenruisi It works, I just tested. But I encounter a new problem, script seems run two times occasionally, so movie list is repeated IMG_63C2B5297531-1

shenruisi commented 2 years ago

@shenruisi It works, I just tested. But I encounter a new problem, script seems run two times occasionally, so movie list is repeated IMG_63C2B5297531-1

This should be an issue of the content script injected at frames. I will mention you to test when the new version is updated.