toMorse

Plays selected text as morse code.

目前為 2015-07-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          toMorse
// @description   Plays selected text as morse code.
// @namespace     https://greasyfork.org/en/users/11891-qon
// @author        Qon
// @include       *
// @include       about:toMorse
// @noframes
// @grant         GM_getValue
// @grant         GM_setValue
// @license       Simple Public License 2.0 (SimPL) https://tldrlegal.com/license/simple-public-license-2.0-%28simpl%29
// @version 0.0.1.20150722035922
// ==/UserScript==

/*
TODO
  GUI
    Volume control
    Speed control
    Pitch control
    Set your own hotkey
  BUG
    perfect Selection animation
*/

var sett = {}
sett['cwpm'] = {def: 20, val: 20, min: 1, max: 100, label: 'Letter WPM', description: 'cwpm'}
sett['ewpm'] = {def: 20, val: 20, min: 1, max: 100, label: 'Effective WPM', description: 'ewpm'}
sett['tone'] = {def: 800, val: 800, min: 200, max: 3200, label: 'Tone frequency', description: 'tone'}
var current = {}

for (var key in sett) {
  if(sett.hasOwnProperty(key)) {
    sett[key]['val'] = GM_getValue(key, sett[key]['val'])
  }
}

function playTextLCWO(charWpm, effectiveWpm, tone, str) {
  var prevAudio = document.getElementById('audioLCWO')
  if(prevAudio) {
    prevAudio.pause()
    prevAudio.remove()
  }
  var audio = document.createElement('audio')
  audio.id = 'audioLCWO'
  audio.src = 'http://cgi2.lcwo.net/cgi-bin/cw.ogg?s='+charWpm+'&e='+effectiveWpm+'&f='+tone+'&t='+str
  audio.addEventListener('ended', function(){document.getElementById('audioLCWO').remove()});
  document.body.appendChild(audio)
  audio.play()
}

function keypress (e) {
  if (!e) e = window.event;
  if (e.ctrlKey && e.key == 'm') {
    playTextLCWO(sett['cwpm']['val'], sett['ewpm']['val'], sett['tone']['val'], window.getSelection().toString())
  }
}
window.addEventListener("keydown", keypress);

if (document.location == 'https://greasyfork.org/en/scripts/11117-tomorse') {
  var settingsdiv = document.createElement('div');
  settingsdiv.id = 'tomorse-settings'
  var h3 = document.createElement('h3')
  h3.innerHTML = 'Script Settings'
  h3.style.marginBottom = '0'
  h3.style.paddingBottom = '0'
  settingsdiv.appendChild(h3)
  var qontdiv = document.createElement('div');
  qontdiv.style.padding = '1em'
  qontdiv.style.margin = '0'
  qontdiv.style.background = '#E6FFE6'

  function setting(name, variable, decription) {
    var span = document.createElement('span')
    span.innerHTML = name+': '
    var inpN = document.createElement('input')
    inpN.id = 'input-'+variable
    inpN.name = variable
    inpN.type = 'number'
    inpN.value = sett[variable]['val']
    var inpRange = document.createElement('input')
    inpRange.id = 'input-range-'+variable
    inpRange.name = variable
    inpRange.type = 'range'
    inpRange.min = sett[variable]['min']
    inpRange.max = sett[variable]['max']
    inpRange.value = sett[variable]['val']
    f = function(ev){
      var el = ev.target
      var inte = parseInt(el.value)
      GM_setValue(el.name, inte)
      sett[el.name]['val'] = inte
      document.getElementById('input-range-'+el.name).value = inte
      document.getElementById('input-'+el.name).value = inte
      if(el.name == 'cwpm' && document.getElementById('wpm-link').checked) {
        document.getElementById('input-range-'+'ewpm').value = inte
        document.getElementById('input-'+'ewpm').value = inte
        GM_setValue('ewpm', inte)
        sett['ewpm']['val'] = inte
      }
    }
    inpN.addEventListener('input', f)
    inpRange.addEventListener('input', f)
    qontdiv.appendChild(span)
    qontdiv.appendChild(inpN)
    qontdiv.appendChild(inpRange)
    qontdiv.appendChild(document.createElement('br'))
  }

  for(var key in sett) {
    if(sett.hasOwnProperty(key)) {
      setting(sett[key]['label'], key, sett[key]['description'])
    }
  }
  var box = document.createElement('input')
  box.id = 'wpm-link'
  box.checked = true
  box.type = 'checkbox'
  var linkSpan = document.createElement('span')
  linkSpan.innerHTML = 'Copy value to "Effective WPM"'
  linkSpan.style.fontSize = '75%'
  linkSpan.style.marginLeft = '100px'
  // linkSpan.style.marginLeft = 'auto'
  qontdiv.insertBefore(linkSpan, qontdiv.getElementsByTagName('br')[0])
  qontdiv.insertBefore(box, qontdiv.getElementsByTagName('br')[0])

  // console.log('QQQ')
  document.getElementById('script-content').appendChild(settingsdiv)
  settingsdiv.appendChild(qontdiv)
}