Skip to content

Update autoconfirm.js#43

Open
JohnyP36 wants to merge 1 commit into
lawfx:masterfrom
JohnyP36:patch-1
Open

Update autoconfirm.js#43
JohnyP36 wants to merge 1 commit into
lawfx:masterfrom
JohnyP36:patch-1

Conversation

@JohnyP36

Copy link
Copy Markdown

See the last 6 comments on issue #25 #25 (comment)

See the last 6 comments on issue #25 #25 (comment)
@Araxeus

Araxeus commented Oct 29, 2021

Copy link
Copy Markdown

can even make the whole extension be:

const script = document.createElement('script');
script.textContent = 'setInterval(() => window._lact = Date.now(), 900000);';
script.onload = function () {
    this.remove();
};
(document.head || document.documentElement).appendChild(script);

btw I have tested this method for hundred of hours and never had problems

@Nomes77

Nomes77 commented Oct 29, 2021

Copy link
Copy Markdown

@Araxeus But now the logging functionality is there. So you can see when it resets the time. Other, like your code, you can't see when it does something.

@Araxeus

Araxeus commented Oct 29, 2021

Copy link
Copy Markdown

The whole point is that you dont need to see anything - this just works no logging needed 😋

logging that the interval is working every 15 min isn't achieving anything IMO (its fine for initial testing, not very useful for deployment)

@JohnyP36

Copy link
Copy Markdown
Author

The whole point is that you dont need to see anything - this just works no logging needed 😋

logging that the interval is working every 15 min isn't achieving anything IMO (its fine for initial testing, not very useful for deployment)

@Araxeus That's true

@Araxeus

Araxeus commented Oct 29, 2021

Copy link
Copy Markdown

yeah well also if u wanna use manifest v3 in chrome it doesn't work this way

you have to inject an external page, like so:

function loadPageAccess() {
    const pageAccess = document.createElement('script');
    pageAccess.src = chrome.runtime.getURL('pageAccess.js');
    pageAccess.onload = function () {
        this.remove();
    };
    (document.head || document.documentElement).appendChild(pageAccess);
}

but then its funny cuz pageAccess.js will be just

setInterval(() => window._lact = Date.now(), 900000);

and in the manifest (should probably also update to v3)

 "web_accessible_resources": [
    {
      "resources": [ "pageAccess.js" ],
      "matches": [ "https://www.youtube.com/*", "https://music.youtube.com/*" ]
    }
  ],

like in my extension https://github.com/Araxeus/Youtube-Volume-Scroll/blob/main/manifest.json

@JohnyP36

Copy link
Copy Markdown
Author

You don't need a background.js anymore than?

Because now it reads:

chrome.runtime.onInstalled.addListener(() => {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
    chrome.declarativeContent.onPageChanged.addRules([
      {
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { hostEquals: 'www.youtube.com' }
          }),
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { hostEquals: 'music.youtube.com' }
          })
        ],
        actions: [new chrome.declarativeContent.ShowPageAction()]
      }
    ]);
  });
});

@Araxeus

Araxeus commented Oct 29, 2021

Copy link
Copy Markdown

I dont know whats the purpose of that popup

you dont have to remove it tho

Comment thread autoconfirm.js

function log(message) {
console.log(`${tag}[${getTimestamp()}] ${message}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be:

    function log(message) {
      console.log(`${tag}[${getMilliseconds()}] ${message}`);
    }

Comment thread autoconfirm.js
let time = asDoubleDigit(dt.getHours()) + ':' + asDoubleDigit(dt.getMinutes()) + ':' + asDoubleDigit(dt.getSeconds());
let time = dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
return time;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be:

    function getMilliseconds() {
      return +new Date();
    }

Comment thread autoconfirm.js
log(`Monitoring YouTube ${isYoutubeMusic ? 'Music ' : ''}for 'Confirm watching?' action...`);
} +
')();';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file can be:

const script = document.createElement('script');
script.textContent = 'setInterval(() => window._lact = Date.now(), 900000);';
script.onload = function () {
    this.remove();
};
(document.head || document.documentElement).appendChild(script);

If you don't need any logging in the console.

@JohnyP36 JohnyP36 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #43 (comment) for a much sorter version.
Besides, your extension will be Manifest v3 (instead of v2).

@JohnyP36 JohnyP36 mentioned this pull request Nov 2, 2021
JohnyP36 added a commit to JohnyP36/YT-Nonstop that referenced this pull request Nov 15, 2021
Make use of YouTube's own events (see lawfx/YoutubeNonStop#43)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants