2Random Wordlist

Generates a random 2 word wordlist

目前為 2020-07-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         2Random Wordlist
// @namespace    https://gf.qytechs.cn/en/users/668074
// @version      0.1
// @description  Generates a random 2 word wordlist
// @author       Two
// @match        https://sketchful.io/
// @grant        none
// ==/UserScript==

(function () {
      'use strict';
      var newHTML = document.getElementById("gameSettings")
      newHTML.innerHTML = `<style>#gravatar
      {
          overflow: hidden;
      }
    textarea {
      resize: none;
    }
      #circle
      {

          float: right;
          height: 39px;
          width: 55px;
          border-radius: 20px;
      }

      #square
      {
          background-color: white;
          float: left;
          display:none;
          height: 0;
          width: 0;
          opacity: 0;

          /* hover OFF */
          -webkit-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
          -moz-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
          -o-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
          -ms-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
          transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
      }

      #square:hover,
      #circle:hover + #square
      {
         display: initial;
          height: 150px;
          width: 400px;
          opacity: 1;
          float:right;
          /* hover ON */
          -webkit-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
          -moz-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
          -o-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
          -ms-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
          transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
      }</style><div id="gravatar">
      <img src="https://cdn0.iconfinder.com/data/icons/navigation-set-arrows-part-one/32/ChevronRight-512.png" id="circle">
      <div id="square">
       <div id="lengtho">
       <a>Length of list</a>

       </div>
            <div id="nw">
       <a>No. of words</a>

       </div>
  <div id="copy">

  </div>

      </div>
  </div>` + newHTML.innerHTML;
      let copy1 = document.createElement('button');
      copy1.innerHTML = "Copy"

      copy1.onclick = function () {
            copy();
      }
      document.getElementById("copy").appendChild(copy1)
      document.getElementById("copy").append(" Remove Duplicates? ")
      let check1 = document.createElement('input');
      check1.setAttribute("class", "check")
      check1.setAttribute("type", "checkbox")
      check1.onchange = function () {

            doWork();
      }
      document.getElementById("copy").appendChild(check1)

      let nw1 = document.createElement("input")
      nw1.setAttribute("placeholder", "Default: 2")
      nw1.setAttribute("class", "nw")
      nw1.setAttribute("type", "number")
      nw1.onchange = function () {
            doWork()
      }
      document.getElementById("nw").appendChild(nw1)
      let lengtho1 = document.createElement("input")
      lengtho1.setAttribute("placeholder", "Default: 1000")
      lengtho1.setAttribute("class", "lengtho")
      lengtho1.setAttribute("type", "number")

      lengtho1.onchange = function () {
            doWork()
      }
      document.getElementById("lengtho").appendChild(lengtho1)




      let result1 = document.createElement("textarea")
      result1.setAttribute("placeholder", "Result will show up here")
      result1.setAttribute("class", "result")
      result1.setAttribute("readonly", "")
      result1.setAttribute("rows", "2")

      let rlist1 = document.createElement("textarea")
      rlist1.setAttribute("placeholder", "List of words to be randomized.")
      rlist1.setAttribute("class", "rList")
      rlist1.setAttribute("rows", "2")
      rlist1.onchange = function () {
            doWork()
      }
      document.getElementById("square").appendChild(rlist1)
      document.getElementById("square").appendChild(result1)





      function doWork() {
            var tries = 0
            var lengtho = document.getElementsByClassName("lengtho")[0].value || 1000
            var l = document.getElementsByClassName("rList")[0].value
            if (!l) return;

            document.getElementsByClassName("result")[0].value = "Loading..."

            l = shorten(l, 20000)
            l = l.split(",")
            l = l.map(f => f.replace(" ", ""))
            if (l.length == 1) {
                  document.getElementsByClassName("result")[0].value = l[0] + " " + l[0]
                  return;
            }
            function getRandomWords(no_words) {
                  var now = document.getElementsByClassName("nw")[0].value || 2
                  var temparr = []
                  for (var e = 0; e < now; e++) {
                        temparr.push(no_words[Math.floor(Math.random() * no_words.length)])
                  }
                  return temparr.join(" ")
            }

            function shorten(str, maxLen, separator = ', ') {
                  if (str.length <= maxLen) return str;
                  return str.substr(0, str.lastIndexOf(separator, maxLen));
            }
            getWord()
            var wordarr = []
            function arraysEqual(_arr1, _arr2) {

                  if (!Array.isArray(_arr1) || !Array.isArray(_arr2) || _arr1.length !== _arr2.length)
                        return false;

                  var arr1 = _arr1.concat().sort();
                  var arr2 = _arr2.concat().sort();

                  for (var i = 0; i < arr1.length; i++) {

                        if (arr1[i] !== arr2[i])
                              return false;

                  }

                  return true;

            }
            function onlyUnique(value, index, self) {
                  return self.indexOf(value) === index;
            }
            function getWord() {
                  var wordd = getRandomWords(l)
                  if (!wordarr) wordarr = []
                  if (document.getElementsByClassName("check")[0].checked) {

                        wordarr.push(wordd)

                  } else {
                        wordarr.push(wordd)
                  }
            }

            for (var i = 0; i < lengtho; i++) {
                  getWord()
            }
            if (document.getElementsByClassName("check")[0].checked) {

                  wordarr = wordarr.filter(onlyUnique)
            }
            var res = document.getElementsByClassName("result")[0]
            res.value = wordarr.toString()
      }
      function copy() {
            var result = document.getElementsByClassName('result')[0]
            result.select();
            document.execCommand('copy');

      }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址