User JS

From Soyjak Wiki, The Free Soycyclopedia
Revision as of 00:53, 3 July 2021 by Onions (talk | contribs) (Onions moved page User JS to Operation Bleached Bowl: Never Forget 159671: test)
Jump to navigationJump to search

On soyjak.party users can add custom javascript under Options->User JS in the top right of the page to customize their browsing experience.

Code Snippets

Preview for Youtube Videos

Show preview for youtube video links.

(function youtubeInlinePreviews() {

const re = /(?:youtube\.com\/watch\?v=|youtu\.be\/)(.{11})/;

const previewTemplate = (videoId) => `<img

style="max-width:255px;max-height:255px"

src="https://i.ytimg.com/vi/${videoId}/hqdefault.jpg"

/>`;

Array.from(document.querySelectorAll(".body a"))

.filter((link) => link.href.match(re))

.forEach((link) => {

const videoId = link.href.match(re)[1];

const inlinePreview = previewTemplate(videoId);

link.innerHTML = inlinePreview;

});

})();

Filter tripchuds

To use it, change "!!TRIP GOES HERE" to any trip you want to filter (ex: !incelchud1 or !!incelchud1), can also be used to filter names if you change

(/class="trip">!!TRIP GOES HERE</)

to

(/class="name">name of the chudcel you want to filter</)

if you want to filter multiple tripchuds, you have to do this

(/class="trip">!!FIRST TRIP CHUD|!SECOND TRIPCHUD|!THIRD TRIPCHUD</)

$(".post")
  .filter(function (index) {
    return this.innerHTML.match(/class="trip">!!TRIP GOES HERE</);
  })
  .each(function (index) {
    let whatToHide = "#" + this.id;
    if (this.id.startsWith("op_")) {
      whatToHide = "#" + this.id.replace("op_", "thread_");
    }
    $(whatToHide).hide();
  });

if (!localStorage.favorites) {
	localStorage.favorites = '[]';
}

Hide tripchud posts from catalog

Hides all tripchud posts from catalog, no exceptions.

// --- start: purgeTripsFromCatalog ---

(function purgeTripsFromCatalog() {
  // If on a catalog page
  if (document.location.href.match(/catalog\.html$/)) {
    // Call the API for that page
    fetch(document.location.href.replace(".html", ".json"))
      .then((res) => res.json())
      .then((json) =>
        json
          // Find the threads where OP is using a tripcode
          .reduce((acc, cur) => [...acc, ...cur.threads], [])
          .filter((op) => op.trip)
          // Hide them
          .forEach((filtered) => $(`div[data-id='${filtered.no}']`).hide())
      );
  }
})();

// --- end: purgeTripsFromCatalog ---