PH Video links

Linkify video titles on PornHub

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         PH Video links
// @version      1.2.1
// @description  Linkify video titles on PornHub
// @author       salad: https://greasyfork.org/en/users/241444-salad
// @include      https://www.pornhub.com/view_video.php?*
// @grant        none
// @namespace    https://greasyfork.org/users/241444
// ==/UserScript==


(function() {

  const playerWrap = document.getElementById('player');
  if(!playerWrap) {
    console.error('playerWrap element not found');
    return;
  }

  let observer;
  let sourceElement;
  const observerConfig = { attributes: true, childList: true, subtree: true };

  // once source is defined, set title element
  const setLink = () => {

    // video title element
    const title = document.querySelector('h1.title>span');

    // video title
    const titleText = title.innerHTML;

    // username if any
    const username = document.querySelector('.video-info-row .usernameWrap');
    const usernameText = (username !== null) ? username.innerText : 'unknown';

    // video source url
    const sourceUrl = sourceElement.getAttribute('src');

    // wrap in a link
    const link = `<a href="${sourceUrl}">${usernameText} - ${titleText}</a>`;

    title.innerHTML = link;

    // also update the page title
    document.title = `${usernameText} - ${titleText}`;

  }

  // Callback function to execute when mutations are observed
  const checkForSource = () => {

      const source = playerWrap.querySelector('source[src]');
      if(source && source.getAttribute('src')) {
        sourceElement = source;
        setLink();
        observer.disconnect();
      }

  };

  observer = new MutationObserver(checkForSource);
  observer.observe(playerWrap, observerConfig);

  // initial run
  checkForSource();

})();