Swinging Words

Random words swing like they're hanging from the page

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Swinging Words
// @namespace    http://swing.words/
// @version      1.0
// @description  Random words swing like they're hanging from the page
// @match        *://*/*
// @grant        none
// @run-at       document-idle
// @license MIT 
// ==/UserScript==

(function () {
  'use strict';

  const CHANCE = 0.1; // 10% of words swing

  const style = document.createElement("style");
  style.textContent = `
    @keyframes swing {
      0%   { transform: rotate(0deg); }
      25%  { transform: rotate(15deg); }
      50%  { transform: rotate(0deg); }
      75%  { transform: rotate(-15deg); }
      100% { transform: rotate(0deg); }
    }

    .swinging-word {
      display: inline-block;
      transform-origin: top center;
      animation: swing 2s ease-in-out infinite;
      margin: 2px;
    }
  `;
  document.head.appendChild(style);

  const paragraphs = document.querySelectorAll("p");
  paragraphs.forEach(p => {
    const text = p.textContent;
    const words = text.split(/(\s+)/); // preserve spaces
    const frag = document.createDocumentFragment();

    words.forEach(word => {
      if (/\S/.test(word) && Math.random() < CHANCE) {
        const span = document.createElement("span");
        span.className = "swinging-word";
        span.textContent = word;
        frag.appendChild(span);
      } else {
        frag.appendChild(document.createTextNode(word));
      }
    });

    p.textContent = ""; // Clear original
    p.appendChild(frag);
  });

  console.log("🎯 Swinging words activated.");
})();