Sha256: 215241899b6aad74e7cf5c6ceb2dc86d233c3ae1b102f0913abcacdad9fa183e

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

/* eslint-disable no-console */
import Copyray from './copyray'
import { isMac } from './util'

declare global {
  interface Window {
    CopyTuner: {
      url: string
      // TODO: type
      data: object
    }
  }
}

import './copyray.css'

// NOTE: 元々railsから出力されいてたマークアップに合わせてひとまず、、
const appendCopyTunerBar = (url: string) => {
  const bar = document.createElement('div')
  bar.id = 'copy-tuner-bar'
  bar.classList.add('copy-tuner-hidden')
  bar.innerHTML = `
    <a class="copy-tuner-bar-button" target="_blank" href="${url}">CopyTuner</a>
    <a href="/copytuner" target="_blank" class="copy-tuner-bar-button">Sync</a>
    <a href="javascript:void(0)" class="copy-tuner-bar-open-log copy-tuner-bar-button js-copy-tuner-bar-open-log">Translations in this page</a>
    <input type="text" class="copy-tuner-bar__search js-copy-tuner-bar-search" placeholder="search">
  `
  document.body.append(bar)
}

const start = () => {
  const { url, data } = window.CopyTuner

  appendCopyTunerBar(url)
  const copyray = new Copyray(url, data)

  document.addEventListener('keydown', (event) => {
    // @ts-expect-error TS2339
    if (copyray.isShowing && ['Escape', 'Esc'].includes(event.key)) {
      copyray.hide()
      return
    }

    if (((isMac && event.metaKey) || (!isMac && event.ctrlKey)) && event.shiftKey && event.key === 'k') {
      copyray.toggle()
    }
  })

  if (console) {
    console.log(`Ready to Copyray. Press ${isMac ? 'cmd+shift+k' : 'ctrl+shift+k'} to scan your UI.`)
  }
}

if (document.readyState === 'complete' || document.readyState !== 'loading') {
  start()
} else {
  document.addEventListener('DOMContentLoaded', () => start())
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
copy_tuner_client-0.13.5 src/main.ts
copy_tuner_client-0.13.3 src/main.ts
copy_tuner_client-0.13.2 src/main.ts
copy_tuner_client-0.13.1 src/main.ts
copy_tuner_client-0.13.0 src/main.ts