Skip to content

Instantly share code, notes, and snippets.

@ShrineFox
Last active November 8, 2023 13:18
Show Gist options
  • Save ShrineFox/f3017d5847a61893eaee9bb4c7028a25 to your computer and use it in GitHub Desktop.
Save ShrineFox/f3017d5847a61893eaee9bb4c7028a25 to your computer and use it in GitHub Desktop.
Twitter/BlueSky Video Background Stylus Theme + Greasemonkey Extension
/* Last Updated 11/08/2023 */
:root
{
--theme: rgba(20, 255, 0, .8);
--theme-transparent: rgba(20, 255, 0, .35);
--image_dimness: rgba(0,0,0,0.2);
--video_opacity: 0.5;
--bgimage: url(https://cdn.discordapp.com/attachments/488899879016595468/1057703830567002132/galaxy.jpg);
--darken: rgba(0,0,0,0.1);
--darken-medium: rgba(0,0,0,0.3);
--darken-strong: rgba(0,0,0,0.8);
--blur: 6px;
}
html
{
background: var(--bgimage) fixed !important;
background-size: cover !important;
}
div#root
{
background: var(--image_dimness) !important;
}
video {
opacity: var(--video_opacity) !important;
}
/* Sidebar option hover */
a.css-175oi2r.r-1loqt21.r-1otgn73.r-1awozwy.r-1xfd6ze.r-18u37iz.r-uaa2di.r-xyw6el.r-3o4zer {
background: transparent !important;
}
a.css-175oi2r.r-1loqt21.r-1otgn73.r-1awozwy.r-1xfd6ze.r-18u37iz.r-uaa2di.r-xyw6el.r-3o4zer:hover
{
background-color: var(--theme-transparent) !important;
}
/* Transparent Bg */
.r-13awgt0, .r-1w88a7h, /* whole app */
.css-175oi2r.r-1pi2tsx:not(.css-175oi2r.r-1niwhzg.r-vvn4in.r-u6sd8q.r-1p0dtai.r-1pi2tsx.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-13qz1uu.r-1wyyakw.r-4gszlv), /* main timeline */
.css-175oi2r.r-1u20jyi.r-u8s1d.r-1ej1qmr.r-ryqm5k, /* right sidebar bg */
.css-175oi2r.r-bnwqim.r-1ipicw7, /* search bar */
.css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-agouwx, /* search bg - 1.52 */
.css-175oi2r.r-kdyh1x.r-rs99b7.r-eqz5dr.r-156q2ks.r-oyd9sg.r-1ipicw7,
.css-175oi2r.r-13awgt0 .css-175oi2r.r-1pi2tsx.r-kemksi .css-175oi2r.r-1pi2tsx .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0.r-1d5kdc7.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0 > div > div,
.css-175oi2r.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu.r-1ljd8xs.r-13l2t4g.r-sa2ff0 div:not(.css-175oi2r.r-1dzdj1l.r-10ptun7.r-1janqcz, .css-175oi2r.r-1ylenci.r-rs99b7.r-1k25im9.r-tuq35u.r-1mhb1uw, .css-1rynq56.r-dnmrzs.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1bymd8e,
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1xfd6ze.r-rs99b7.r-knv0ih.r-1e081e0.r-1f1sjgu, .css-1rynq56.r-8akbws.r-krxsd3.r-dnmrzs.r-1udh08x.r-1udbk01), /* settings option bg */
.css-175oi2r.r-m611by, /* Select Account bg */
button.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-18u37iz.r-10sqg0u.r-1mmae3n.r-284m6k /* alternate account sign-in in settings */
{
background-color: transparent !important;
border: 0px solid transparent !important;
}
/* Content filtering option button bg color */
.css-175oi2r.r-18u37iz.r-1n0xq6e > div {
background-color: var(--theme) !important;
}
.css-175oi2r.r-1awozwy.r-1llaxt6.r-uvuy5l.r-1777fci.r-cfp7ip /* Mobile compose button */
{
background-image: linear-gradient(3.02408rad, var(--theme), var(--theme)) !important;
}
/* Darken/blur post background */
.css-175oi2r.r-5kkj8d.r-1sp51qo.r-xd6kpl.r-ry3cjt, /* main timeline */
.css-175oi2r.r-5kkj8d.r-1sp51qo.r-ry3cjt, /* search timeline */
.css-175oi2r.r-1sp51qo.r-xd6kpl.r-ry3cjt.r-13yce4e, /* feed alternating post bg */
.css-175oi2r.r-1sp51qo.r-ry3cjt.r-13yce4e.r-l4nmg1,
.css-175oi2r.r-12rqra3.r-s0e3za.r-5t7p9m, /* view full thread link bg */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-qklmqi.r-5kkj8d.r-18u37iz.r-1wtj0ep.r-6gpygo.r-ymttw5.r-1yzf0co, /* see more from discover link bg */
.css-175oi2r.r-y47klf.r-ymttw5.r-1vvnge1.r-1ipicw7, /* search bar bg */
/*.css-175oi2r.r-q5xsgd.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu.r-1ljd8xs.r-13l2t4g.r-sa2ff0, feed timeline bg */
.css-175oi2r.r-1xfd6ze.r-rs99b7.r-f1odvy, /* embed description bg */
a.css-175oi2r.r-1xfd6ze.r-rs99b7.r-14gqq1x.r-15d164r, /* link embed bg */
.css-175oi2r.r-105ug2t, /* edit feeds bg */
.css-175oi2r.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu.r-1ljd8xs.r-13l2t4g.r-sa2ff0, /* settings bg */
.css-175oi2r.r-1loqt21.r-1otgn73.r-rs99b7.r-18u37iz.r-1777fci.r-utggzx.r-1w50u8q.r-b8lwoo.r-5qlx7g.r-1ljd8xs.r-1vznrp2, /* Appearance option buttons */
.css-175oi2r.r-1loqt21.r-1otgn73.r-gxnn5r.r-rs99b7.r-18u37iz.r-1777fci.r-utggzx.r-1w50u8q.r-b8lwoo,
.css-175oi2r.r-1loqt21.r-1otgn73.r-gxnn5r.r-rs99b7.r-18u37iz.r-1777fci.r-utggzx.r-1w50u8q.r-b8lwoo,
.css-175oi2r.r-5kkj8d.r-1ss6j8a.r-1qortcd.r-vmopo1, /* single post bg */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-5kkj8d.r-18u37iz.r-1mi0q7o.r-d9fdf6.r-m611by, /* compose reply bg */
.css-175oi2r.r-5kkj8d.r-1hfyk0a, /* reply bg */
.css-175oi2r.r-1hfyk0a.r-13yce4e,
.css-175oi2r.r-iphfwy.r-779j7e.r-tskmnb, /* profile header bg */
.css-175oi2r.r-18u37iz.r-779j7e,
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-5kkj8d.r-d9fdf6.r-oyd9sg, /* Select Account options */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-5kkj8d.r-d9fdf6.r-qklmqi.r-117bsoe.r-5njf8e,
.r-m7buhn, /* Feedback button */
.css-175oi2r.r-1dzdj1l.r-117bsoe.r-nsbfu8 /* home feed preferences option bg */
{
background-color: var(--darken) !important;
backdrop-filter: blur(var(--blur)) !important;
border: 0px solid transparent !important;
}
a.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-uekwnc.r-13yce4e, /* search users dropdown */
a.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-5kkj8d.r-uekwnc, /* users lists (following, liked, etc.) */
.css-175oi2r.r-1pi2tsx.r-1ljd8xs.r-13l2t4g.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu > div, /* moderation tab bg */
.css-175oi2r.r-13awgt0 .css-175oi2r.r-1pi2tsx.r-kemksi .css-175oi2r.r-1pi2tsx .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0.r-1d5kdc7.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af .css-175oi2r.r-13awgt0 .css-175oi2r.r-13awgt0 .css-175oi2r.r-eqz5dr.r-1pi2tsx .css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-1sncvnh .css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-1sncvnh .css-175oi2r.r-q5xsgd.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu.r-1ljd8xs.r-13l2t4g.r-sa2ff0 > div > div,
/* profile / feed header bg */
.css-175oi2r.r-1loqt21.r-1otgn73.r-1xfd6ze.r-rs99b7.r-knv0ih.r-1mmae3n.r-3o4zer, /* quote post bg */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1xfd6ze.r-rs99b7.r-knv0ih.r-1e081e0.r-1f1sjgu,
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1llaxt6.r-1e7him5.r-1guathk.r-1f1sjgu, /* BlueSky Sign In Button */
button.css-175oi2r.r-1loqt21.r-1otgn73.r-1fuqb1j.r-11f147o.r-gu64tb, /* settings toggle bg */
button.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1tw7wh.r-18u37iz.r-1777fci.r-1rngwi6.r-1yd117h.r-cxgwc0, /* Edit profile button */
.css-175oi2r.r-y47klf.r-1559e4e.r-3pj75a.r-1ipicw7, /* search bar bg */
button.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1tw7wh.r-18u37iz.r-1777fci.r-1rngwi6.r-1yd117h /* follow similar users button */
{
background: var(--darken-medium) !important;
background-color: var(--darken-medium) !important;
backdrop-filter: blur(var(--blur)) !important;
border: 0px solid transparent !important;
}
.css-175oi2r.r-1xfd6ze.r-rs99b7.r-p1pxzi.r-d0c3f3.r-r8bmzb.r-1ye8kvj.r-1mkv55d.r-lzsi8w.r-13qz1uu, /* post composition bg */
.css-175oi2r.r-11ab3e.r-126c2a1.r-krx8kp.r-1xfd6ze.r-919cjt.r-kc8jnq.r-s1qlax.r-oyd9sg.r-1uudbju.r-199as6u, /* popout menu */
.css-175oi2r.r-1xfd6ze.r-rs99b7.r-1tsuqlv.r-7h7f8p.r-1guathk.r-tvv088.r-lrx3fh, /* invite a friend modal bg */
.css-175oi2r.r-18u37iz.r-szihnw /* header bg */
{
background: var(--darken-strong) !important;
backdrop-filter: blur(var(--blur)) !important;
border: 0px solid transparent !important;
}
.css-175oi2r.r-1jj8364.r-lchren.r-1ye8kvj.r-13qz1uu.r-1ljd8xs.r-13l2t4g.r-sa2ff0 /* timeline border color */
{
border-color: transparent !important;
}
/* New Post Button - doesn't work in 1.52 */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-wzwllv.r-1fuqb1j.r-18u37iz.r-1777fci.r-15d164r.r-19u6a5r.r-1x0uki6.r-ymttw5.r-1w50u8q.r-1n20pny, /* in sidebar */
.css-175oi2r.r-y47klf.r-d9fdf6.r-1rcbeiy, /* in post editor */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1xfd6ze.r-18u37iz.r-1cmwbt1.r-1777fci.r-1ybube5.r-c8eef1.r-779j7e.r-1f1sjgu, /* discover new feeds button */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1llaxt6.r-rs99b7.r-te4v75.r-18u37iz.r-1sn7ly2.r-1777fci.r-8l2rlp.r-u8s1d.r-a2mu05.r-8br3cv, /* load latest posts button (bottom) */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1llaxt6.r-rs99b7.r-18u37iz.r-1777fci.r-8l2rlp.r-1guathk.r-23eiwj.r-u8s1d.r-lyppvc.r-1sffzi, /* load latest posts button (top) */
.css-175oi2r.r-1dzdj1l.r-10ptun7.r-1janqcz.r-1ow6zhx, /* Settings require alt txt button */
.css-175oi2r.r-1dzdj1l.r-10ptun7.r-1janqcz, /* Settings experimental app view proxy button */
.r-wzwllv /* new post button 1.52 */
{
background-color: var(--theme-transparent) !important;
border: 0px solid transparent !important;
}
.css-1rynq56.r-1i10wst, /* Cancel post link */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73 .css-1rynq56:nth-child(1):not(.css-1rynq56.r-8akbws.r-krxsd3.r-dnmrzs.r-1udh08x.r-1udbk01, a.css-1rynq56.r-dnmrzs.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1loqt21), /* Cancel search link */
.css-1rynq56.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1jizoa0, /* Translate post link */
.css-175oi2r.r-1x0uki6.r-utggzx a, /* Sidebar links */
.css-175oi2r.r-12rqra3.r-s0e3za.r-5t7p9m > *, /* view full thread link */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-qklmqi.r-5kkj8d.r-18u37iz.r-1wtj0ep.r-6gpygo.r-ymttw5.r-1yzf0co > *, /* see more from discover link */
a.css-1qaijid.r-13awgt0.r-1loqt21, /* tagged username link */
.css-175oi2r.r-1loqt21.r-1otgn73.r-1awozwy.r-1llaxt6.r-18u37iz.r-uaa2di.r-7e3msg.r-1guathk.r-23eiwj .css-1rynq56, /* new mute list link */
.r-yovm8p, /* BlueSky text */
a.css-1rynq56.r-1mf7evn.r-1loqt21, /* BlueSky Footer Links */
.css-1rynq56.r-1hfyk0a, /* Feedback button link */
.css-175oi2r.r-18u37iz.r-1cmwbt1 .css-146c3p1 /* similar users Follow button */
{
color: var(--theme) !important;
}
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1j3t67a svg path /* attach image to post icon */,
.css-175oi2r.r-1loqt21.r-1otgn73.r-1awozwy.r-qklmqi.r-13awgt0.r-18u37iz.r-i023vh svg path, /* edit my feeds icons */
.css-175oi2r.r-1loqt21.r-1otgn73.r-1fuqb1j.r-779j7e.r-5njf8e.r-1aockid svg path, /* mute list plus button */
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1h84pjw.r-18u37iz.r-1sp51qo.r-d9fdf6.r-m7buhn svg path /* Feedback button icon */
{
fill: var(--theme);
}
/* Post character limit radial */
.css-175oi2r.r-1niwhzg.r-1udh08x svg path,
.css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-1sncvnh svg path /* edit my feeds gear icon */
{
stroke: var(--theme) !important;
}
.css-175oi2r.r-1i6wzkk.r-lrvibr.r-1loqt21.r-1otgn73.r-1awozwy.r-1llaxt6.r-rs99b7.r-18u37iz.r-1777fci.r-8l2rlp.r-1guathk.r-23eiwj.r-u8s1d.r-lyppvc.r-1sffzi .css-1rynq56 /* Button text */ {
color:white !important;
}
/* All links
.css-175oi2r.r-18u37iz a {
color: var(--theme) !important;
} */
/* All text
.css-1rynq56 {
color: var(--theme) !important;
}*/
/* bluesky 1.52 fixes */
/* Right Sidebar */
.css-175oi2r.r-168uwkl.r-rsyp9y.r-u8s1d.r-1ej1qmr.r-ryqm5k {
background-color: transparent !important;
}
/* All links aside from profile names */
a:not(a.css-146c3p1.r-dnmrzs.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1loqt21, a.css-1jxf684.r-dnmrzs.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1loqt21),
.css-175oi2r.r-1i6wzkk *:not(.r-84gixx *), /* Most clickable elements other than heart icon */
.css-175oi2r.r-1awozwy.r-5kkj8d.r-18u37iz * * *:not(.css-175oi2r.r-1niwhzg.r-1udh08x *), /* Emoji Button in New Post composer */
.css-146c3p1.r-1udh08x.r-1udbk01.r-3s2u2q.r-1iln25a.r-1jizoa0 /* Language Option in New Post composer */
{
color: var(--theme) !important;
stroke: var(--theme) !important;
fill: var(--theme-transparent) !important;
background-image: none !important;
background-color: transparent !important;
}
/* Liked post heart button */
.r-84gixx path {
fill: var(--theme) !important;
}
/* Based on Starry by birb-naise, edited by ShrineFox
Original Source: https://userstyles.org/styles/180895/starry-twitter */
:root {
--theme: rgba(0,255,0,.8);
--bg-op: 0.3;
--tweet-op: 0.3;
--lettercase: initial;
--video_opacity: 0.5;
}
html {
background-size: cover !important;
}
.videobg {
opacity: var(--video_opacity) !important;
}
/*darken bg*/
.css-1dbjc4n.r-kemksi.r-1kqtdi0.r-1ljd8xs.r-13l2t4g.r-1phboty.r-16y2uox.r-1jgb5lz.r-11wrixw.r-61z16t.r-1ye8kvj.r-13qz1uu.r-184en5c {
backdrop-filter: blur(6px) !important;
}
/* Darken tabs at top (username, for you, following, lists...) */
.css-1dbjc4n.r-18u37iz.r-16y2uox.r-1wbh5a2.r-tzz3ar.r-1pi2tsx.r-lltvgl.r-buy8e9.r-mfh4gg.r-2eszeu.r-hbs49y,
.r-1h3ijdo {
background: rgba(0,0,0,0.5) !important;
}
/* remove original bg */
body {
background: transparent !important;
}
.css-1dbjc4n{
background-color: transparent;
border: none;
}
/* tweet bg */
.r-1ljd8xs {
background: rgba(0,0,0,var(--tweet-op)) !important;
}
/* misc bg fixes */
.r-k200y, /* dm(recipient) */
.r-1r5jyh0, /* profile hover */
.r-1ljd8xs:nth-child(2), /* pic preview sidebar */
.r-1ipicw7, /* profile switcher */
.r-h3f8nf, /* search popup */
.r-1jte41z, /* mini messages window */
.r-htvplk, /* big pop-ups */
.r-1upvrn0, /* alt text */
.r-adacv, /* qrt */
.r-1q9bdsx { /* reply restriction */
background: rgba(0,0,0,.8) !important;
}
/* light mode fixes */
.r-1re7ezh, .r-18jsvk2, .r-3s2u2q .r-qvutc0 {
color: #dedede !important;
}
.r-9ilb82, .r-14j79pv, .r-1bwzh9t {
color: #a9a9a9
}
.r-z2wwpe:not(.r-eqz5dr) { /* options menu */
background: rgba(0,0,0,.8) !important;
}
/* letter case */
.r-poiln3 {
text-transform: var(--lettercase) !important;
}
/* letter case */
.r-poiln3 {
text-transform: var(--lettercase) !important;
}
/* theme color */
a:not(.r-9ilb82):not(.r-14j79pv):not(.r-111h2gw),
.r-1cvl2hr, /* show x tweets + thread */
.r-1pp923h > div:nth-child(1), /* sidebar show more */
.r-19wmn03, /* icons */
.r-9cviqr{ /* verified */
color: var(--theme) !important;
}
::selection, /* text highlight */
.r-19u6a5r .r-15ysp7h, /* sidebar follow */
.r-1waj6vr, /* new tweet button */
.r-l5o3uw, /* new tweet + outgoing DM */
.r-m5arl1, /* reply/thread line */
.r-1bimlpy, /* poll bars */
.r-10u4nep, /* video scrubber */
.r-1xfd6ze .r-1pz39u2 { /* video progress bar */
background: var(--theme) !important;
}
/* remove footer */
.r-1yadl64 nav.r-18u37iz {
display: none;
}
// Original by zhuzemin, edited by ShrineFox
// ==UserScript==
// @name video_background
// @name:zh-CN video_background
// @name:zh-TW video_background
// @name:ja video_background
// @namespace video_background
// @supportURL https://github.com/zhuzemin
// @description:zh-CN use video as page background
// @description:zh-TW use video as page background
// @description:ja use video as page background
// @description use video as page background
// @include https://twitter.com/*
// @include http://twitter.com/*
// @include https://easymode.im/*
// @include https://bsky.app/*
// @exclude *://*.jpg
// @exclude *://*.gif
// @exclude *://*.png
// @exclude *://*.mp4
// @exclude *://*.swf
// @exclude *://*.pdf
// @exclude https://anime1.me
// @version 1.94
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// @author zhuzemin
// @license Mozilla Public License 2.0; http://www.mozilla.org/MPL/2.0/
// @license CC Attribution-ShareAlike 4.0 International; http://creativecommons.org/licenses/by-sa/4.0/
// @connect-src 127.0.0.1
// ==/UserScript==
var config = {
'debug':false
}
var debug = config.debug ? console.log.bind(console) : function () {
};
var host='http://127.0.0.1/';
var bgColor='#D8E0E0';
var rndStart=true;
var videoList;
var dirList;
var urlRoot;
var usedList=[];
var dirCount=0;
var hostname;
var textColorList;
var ytbList;
var ytbEnable;
// prepare UserPrefs
setUserPref(
'urlRoot',
host+'******',
'Set root url',
`Url from HFS.(.mp4 or dir)`,
','
);
setUserPref(
'ytbPlaylistUrl',
'https://www.youtube.com/playlist?list=PLmlTcWwPyp188O1lK2fyYA_WFckZNrb0b',
'Set Youtube Playlist url',
`Youtube Playlist url`,
','
);
/*setUserPref(
'textBGcolorOpacity',
'0.95',
'Set Text BG-Color Opacity',
`Opacity: `,
','
);*/
class ObjectRequest{
constructor(url) {
this.method = 'GET';
this.url = url;
this.data=null,
this.headers = {
'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
//'Accept': 'application/atom+xml,application/xml,text/xml',
//'Referer': window.location.href,
};
this.charset = 'text/plain;charset=utf8';
this.other=null;
}
}
var init = function () {
if (window.self === window.top || window.location.href.includes('https://www.youtube.com/embed/')) {
textBGcolorOpacity = GM_getValue('textBGcolorOpacity');
if (textBGcolorOpacity == undefined || textBGcolorOpacity == '') {
textBGcolorOpacity = 0.95;
}
else{
textBGcolorOpacity=parseFloat(textBGcolorOpacity);
}
ytbEnable = GM_getValue('ytbEnable');
if (ytbEnable != undefined) {
if (ytbEnable == 'true') {
ytbEnable = true;
}
else if (ytbEnable == 'false') {
ytbEnable = false;
}
}
ytbList = GM_getValue('ytbList');
if (ytbList == undefined || ytbList == '') {
ytbList = [];
}
urlRoot = GM_getValue('urlRoot');
if (urlRoot == undefined || urlRoot == '') {
urlRoot = null;
}
videoList = GM_getValue('videoList');
if (videoList == undefined || videoList == '') {
videoList = [];
}
/*dirList = GM_getValue('dirList');
if (dirList == undefined || dirList == '') {
dirList = [];
}
debug(dirList);*/
var blockList = GM_getValue('blockList');
if (blockList == undefined || blockList == '') {
blockList = [];
}
else {
blockList= blockList.filter(function(item, pos) {
return blockList.indexOf(item) == pos;
})
}
debug('blockList: '+blockList);
textColorList = GM_getValue('textColorList');
if (textColorList == undefined || textColorList == '') {
textColorList = [];
}
else {
textColorList= textColorList.filter(function(item, pos) {
return textColorList.indexOf(item) == pos;
})
}
debug('textColorList: '+textColorList);
/*var lastTime=GM_getValue('lastTime')||0;
var present=parseInt(new Date(). getTime()/1000);
debug(present-parseInt(lastTime));
if(present-parseInt(lastTime)>86400){
videoList=[];
dirList=[];
GM_setValue('lastTime',present);
GM_setValue('videoList',JSON.stringify(videoList));
GM_setValue('dirList',JSON.stringify(dirList));
}*/
if (!window.location.href.includes('https://www.youtube.com/embed/')) {
hostname = getLocation(window.location.href).hostname;
CreateButton('Text BG-color', function () {
var index = textColorList.indexOf(hostname);
var divList = document.querySelectorAll('div');
if (index == -1) {
for (var div of divList) {
div.style.backgroundColor = bgColor;
//div.style.opacity=textBGcolorOpacity;
}
textColorList.push(hostname);
}
else {
for (var div of divList) {
div.style.backgroundColor = '';
//div.style.opacity=1;
}
textColorList.splice(index, 1);
}
debug('textColorList: '+textColorList);
GM_setValue('textColorList', textColorList);
}, 36);
CreateButton('Clear file list', function () {
dirList = [];
videoList = [];
ytbList = [];
GM_setValue('videoList', videoList);
GM_setValue('dirList', dirList);
GM_setValue('ytbList', ytbList);
}, 72);
CreateButton('Add/Del Block List', function (e) {
var msg;
var index = blockList.indexOf(hostname);
if (index > -1) {
blockList.splice(index, 1);
msg = 'Del Success';
}
else {
blockList.push(hostname);
msg = 'Add Success';
}
GM_setValue('blockList', blockList);
e.target.innerHTML = msg;
setTimeout(function () {
e.target.innerHTML = 'Add/Del Block List';
}, 1000);
}, 108);
CreateButton('Youtube Enable/Disable', function (e) {
var msg;
if (ytbEnable) {
ytbEnable = false;
msg = 'Youtube Disable';
}
else {
ytbEnable = true;
msg = 'Youtube Enable';
}
GM_setValue('ytbEnable', ytbEnable);
e.target.innerHTML = msg;
setTimeout(function () {
e.target.innerHTML = 'Youtube Enable/Disable';
}, 1000);
}, 144);
if (!blockList.includes(hostname)) {
if (urlRoot != null && !ytbEnable) {
urlRoot = urlRoot.replace(/http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\//, host);
if (/\.mp4$/.test(urlRoot)) {
insertVideo(urlRoot);
}
else {
if (videoList.length == 0) {
//var obj = new ObjectRequest(urlRoot);
var obj = new ObjectRequest(urlRoot + '?tpl=list&folders-filter=\\\\&recursive');
request(obj, HandleHFS);
debug(urlRoot);
}
else {
videoShuffle(insertVideo);
}
}
}
else if (ytbEnable) {
if (ytbList.length == 0) {
var ytbPlaylistUrl = GM_getValue('ytbPlaylistUrl');
if (ytbPlaylistUrl == undefined || ytbPlaylistUrl == '') {
ytbPlaylistUrl = null;
}
if (ytbPlaylistUrl != null) {
ytbPlaylistUrl = ytbPlaylistUrl.match(/https:\/\/www.youtube.com\/playlist\?list=(.*)$/);
if (ytbPlaylistUrl != null) {
ytbPlaylistUrl = ytbPlaylistUrl[1];
ytbPlaylistUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+id&playlistId=' + ytbPlaylistUrl + '&key=AIzaSyAbzugt7o1RRhBVDyPyZxZTeriH-3Ogtkg';
debug('ytbPlaylistUrl: ' + ytbPlaylistUrl);
var obj = new ObjectRequest(ytbPlaylistUrl);
request(obj, function (respObj) {
var json = JSON.parse(respObj.responseText);
debug('json: ' + json);
for (var item of json.items) {
var videoId = item.snippet.resourceId.videoId;
var videoUrl = 'https://www.youtube.com/embed/' + videoId + '?controls=0&autoplay=1&mute=1';
ytbList.push(videoUrl);
}
GM_setValue('ytbList', ytbList);
videoList = ytbList;
videoShuffle(insertYtb);
});
}
}
}
else {
videoList = ytbList;
videoShuffle(insertYtb);
}
}
}
}
else if (window.location.href.includes('https://www.youtube.com/embed/')) {
var video = document.querySelector('video.video-stream.html5-main-video');
setTimeout(function () {
var randomNum = Math.floor(Math.random() * (video.duration - 0));
video.currentTime=randomNum;
},5000);
var interval=setInterval(function () {
if(parseInt(video.currentTime)==parseInt(video.duration)){
videoList=ytbList;
videoShuffle(insertYtb);
clearInterval(interval);
}
},15000);
var frame=document.querySelector('#video_bg');
window.addEventListener('message', function (e) {
debug(e.data);
if (e.data == "pause") {
if(frame!=null){
frame.contentWindow.postMessage("pause", "*");
}
else {
video.pause();
}
}
else if (e.data == 'play') {
if(frame!=null){
frame.contentWindow.postMessage("play", "*");
}
else {
video.play();
}
}
});
}
}
}
function CreateButton(text,func,positionBtm){
var btn=document.createElement("button");
btn.type="button";
btn.innerHTML=text;
btn.style=`
position: fixed;
right: 0px;
bottom: `+positionBtm+`px;
z-index: 10000;
opacity:0.1;
`;
if(positionBtm!=0&&positionBtm!=36){
btn.style.display='none';
document.body.firstChild.addEventListener('mouseover',function () {
btn.style.display='block';
});
document.body.firstChild.addEventListener('mouseout',function () {
setTimeout(function () {
btn.style.display='none';
},3000);
});
}
btn.addEventListener('click',func);
btn.addEventListener('mouseout',function () {
btn.style.opacity=0.1;
});
btn.addEventListener('mouseover',function () {
btn.style.opacity=1;
});
document.body.insertBefore(btn,document.body.firstChild);
}
function HandleHFS(responseObj) {
if (responseObj.status == 200) {
var fileList=responseObj.responseText.split('\r\n');
debug(fileList);
for(var file of fileList){
if(/\.mp4$/.test(file)){
videoList.push(file);
GM_setValue('videoList',videoList);
}
}
videoShuffle(insertVideo);
}
}
/*
function HandleHFS(responseObj){
if(responseObj.status==200){
if(dirCount!=0){
dirCount--;
}
debug('dirCount: '+dirCount);
var dom = new DOMParser().parseFromString(responseObj.responseText, "text/html");
var files = dom.querySelector('#files');
var trList=files.querySelectorAll("tr");
for(var tr of trList){
var a=tr.querySelector('a');
debug('a.href: '+a.href);
var url=a.href.replace(/https?:\/\/.*\/([^\/]*((\.mp4)|\/)$)/, function(match, $1, $2, offset, original){ return responseObj.finalUrl+$1;})
debug('url: '+url);
if(/\.mp4$/.test(a.textContent)&&!videoList.includes(url)){
videoList.push(url);
GM_setValue('videoList',JSON.stringify(videoList));
}
else if(a.textContent!='Name'){
var img=a.querySelector('img');
debug(img.src);
if(img.src.includes('/~img_folder')){
if(dirList.length!=0){
debug(dirList)
for(var existUrl of dirList){
if(existUrl.includes(url)){
break;
}
else if(existUrl==dirList[dirList.length-1]){
debug('existUrl: '+existUrl+' & '+'url: '+url);
dirCount++;
var obj=new ObjectRequest(url);
dirList.push(url);
GM_setValue('dirList',JSON.stringify(dirList));
request(obj,HandleHFS);
}
}
}
else {
dirCount++;
dirList.push(url);
GM_setValue('dirList',JSON.stringify(dirList));
var obj=new ObjectRequest(url);
request(obj,HandleHFS);
}
}
}
if (tr==trList[trList.length-1]&&dirCount==0) {
videoShuffle();
if (textColorList.includes(hostname)) {
var divList=document.querySelectorAll('div');
for (var div of divList){
div.style.backgroundColor='#D8E0E0';
}
}
}
}
dirCount--;
}
}
*/
window.addEventListener('DOMContentLoaded', init);
function request(object,func) {
var retries = 3;
GM_xmlhttpRequest({
method: object.method,
url: object.url,
data: object.data,
headers: object.headers,
overrideMimeType: object.charset,
timeout:120000,
//synchronous: true
onload: function (responseDetails) {
//debug(responseDetails);
if (responseDetails.status != 200&&responseDetails.status != 302) {
// retry
if (retries--) { // *** Recurse if we still have retries
setTimeout(request,2000);
return;
}
}
//Dowork
func(responseDetails,object.other);
},
ontimeout: function (responseDetails) {
debug(responseDetails);
//Dowork
func(responseDetails,object.other);
},
ononerror: function (responseDetails) {
debug(responseDetails);
//Dowork
func(responseDetails,object.other);
}
})
}
function setUserPref(varName, defaultVal, menuText, promtText, sep){
GM_registerMenuCommand(menuText, function() {
var val = prompt(promtText, GM_getValue(varName, defaultVal));
if (val === null) { return; } // end execution if clicked CANCEL
// prepare string of variables separated by the separator
if (sep && val){
var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g'); // trim space/s around separator & trim repeated separator
var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
//val = val.replace(pat1, sep).replace(pat2, '');
}
//val = val.replace(/\s{2,}/g, ' ').trim(); // remove multiple spaces and trim
GM_setValue(varName, val);
// Apply changes (immediately if there are no existing highlights, or upon reload to clear the old ones)
//if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
//else location.reload();
});
}
function videoShuffle(func) {
debug('videoShuffle');
debug('videoList: '+videoList);
for(var used of usedList){
var index = videoList.indexOf(used);
if (index > -1) {
videoList.splice(index, 1);
}
}
var randomNum = Math.floor(Math.random() * (videoList.length - 0));
if(window.location.href.includes('https://www.youtube.com/embed/')){
videoList = ytbList;
}
var url=videoList[randomNum];
/*if(rndStart){
if(ytbEnable&&!window.location.href.includes('https://www.youtube.com/embed/')){
var videoId=url.match(/https:\/\/www.youtube.com\/embed\/(.*)\?controls=0&autoplay=1&mute=1/);
videoId=videoId[1];
var urlVidInfo='https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id='+videoId+'&key=AIzaSyAbzugt7o1RRhBVDyPyZxZTeriH-3Ogtkg';
var obj=new ObjectRequest(urlVidInfo);
request(obj,function (respObj) {
var json=JSON.parse(respObj.responseText);
for(var item of json.items){
if(item.id==videoId){
debug(JSON.stringify(json));
var duration=item.contentDetails.duration;
debug(duration);
var reptms = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/;
var hours = 0, minutes = 0, seconds = 0, totalseconds;
if (reptms.test(duration)) {
var matches = reptms.exec(duration);
debug(matches);
if (matches[1]) hours = Number(matches[1]);
if (matches[2]) minutes = Number(matches[2]);
if (matches[3]) seconds = Number(matches[3]);
totalseconds = hours * 3600 + minutes * 60 + seconds;
}
randomNum = Math.floor(Math.random() * (totalseconds - 0));
url='https://www.youtube.com/embed/'+videoId+'?controls=0&autoplay=1&mute=1&start='+randomNum;
debug(url);
func(url);
}
}
})
}
else{
func(url);
}
}*/
func(url);
if (textColorList.includes(hostname)) {
var divList=document.querySelectorAll('div');
for (var div of divList){
div.style.backgroundColor=bgColor;
//div.style.opacity=textBGcolorOpacity;
}
}
}
function insertVideo(url) {
debug('insertVideo');
var video = document.createElement("video");
video.className = 'videobg';
video.style = 'width:100%;opacity:1';
video.src = url;
video.autoplay = true;
video.muted=true;
video.loop=true;
var div = document.createElement("div");
div.style = "width:100%; position: fixed; top: 0; left: 0; z-index: -100; background-color: rgba(0,0,0,1)";
div.insertBefore(video, null);
debug(url);
document.body.insertBefore(div, null);
window.addEventListener("focus", function () {
video.play();
});
window.addEventListener("blur", function () {
video.pause();
});
video.addEventListener('onended',function () {
document.removeChild(div);
videoShuffle(insertVideo);
});
video.addEventListener('loadeddata', (event) => {
var randomNum = Math.floor(Math.random() * (video.duration - 0));
video.currentTime=randomNum;
});
usedList.push(url);
}
function getLocation(href) {
var l = document.createElement("a");
l.href = href;
return l;
}
function insertYtb(url) {
debug('insertYtb');
if(window.location.href.includes('https://www.youtube.com/embed/')) {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
}
var iframe = document.createElement("iframe");
iframe.id='video_bg';
iframe.style = 'width:100%;height:100%;';
iframe.src = url;
iframe.allow = "accelerometer;";
iframe.frameborder='0';
var div = document.createElement("div");
div.style = "width:100%; height:100%;position: fixed; top: 0; left: 0; z-index: -100;";
div.insertBefore(iframe, null);
debug(url);
document.body.insertBefore(div, null);
window.addEventListener("focus", function () {
iframe.contentWindow.postMessage("play", "*");
});
window.addEventListener("blur", function () {
iframe.contentWindow.postMessage("pause", "*");
});
usedList.push(url);
}
function iframeRef( frameRef ) {
return frameRef.contentWindow
? frameRef.contentWindow.document
: frameRef.contentDocument
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment