SyncClipboard:跨平台&网络的剪贴板同步方案

2、使用Autox.js
到这里下载AutoX安卓客户端,安装之后,导入 js 配置,并修改配置中的 url(也就是你的服务器连接地址),username(用户名) 和 token(密码)。
Autox.js文件:

// START  User Config  
const url = 'http://192.168.2.2:5033'
const username = 'admin'
const token = 'admin'
const intervalTime = 3 * 1000                           // 3 seconds
const showToastNotification = true
// END    User Config  

const axios = require('axios');

const authHeader = 'basic ' + $base64.encode(`${username}:${token}`)

let urlWithoutSlash = url   
while (urlWithoutSlash.endsWith('/'))
    urlWithoutSlash = url.substring(0, url.length - 1)
const apiUrl = urlWithoutSlash + '/SyncClipboard.json'

let running = false
let remoteCache;

function loop() {
    if (!device.isScreenOn())
        return
    if (running)
        return
    running = true

    upload()
        .then(ifContinue => {
            if (ifContinue)
                download()
        })
        .then(() => { running = false })
        .catch(error => {
            running = false
            toast('Failed: \n' + error)
        });
}

function download() {
    axios({
        method: 'get',
        url: apiUrl,
        responseType: 'json',
        headers: { 'authorization': authHeader },
    })
        .then(res => {
            if (res.status < 200 || res.status >= 300) {
                throw res.status + ' ' + res.statusText
            } else {
                var profile = res.data;
                if (profile.Type != 'Text')
                    return

                var text = profile.Clipboard
                if (text != remoteCache) {
                    remoteCache = text
                    setClip(text)
                    if(showToastNotification)
                        toast('Cipboard Setted\n' + text)
                }
            }
        })
}

function upload() {
    let text = getClip()
    if (text != remoteCache && text != null && text.length != 0) {
        return axios({
            method: 'put',
            url: apiUrl,
            headers: {
                'authorization': authHeader,
                'Content-Type': 'application/json',
            },
            data: {
                'File': '',
                'Clipboard': text,
                'Type': 'Text'
            }
        }).then(res => {
            if (res.status < 200 || res.status >= 300) {
                throw res.status + ' ' + res.statusText
            }
            remoteCache = text
            return false
        })
    }
    return Promise.resolve(true);
}

setInterval(loop, intervalTime)

中也可以直接编辑 js 脚本:
SyncClipboard:跨平台&网络的剪贴板同步方案

修改完之后,把 Autox.js 这个 app 的后台运行权限打开,确保不会被系统杀掉。为 js 配置脚本添加一个定时任务,让 Autox.js 启动时就自动运行。

SyncClipboard:跨平台&网络的剪贴板同步方案

SyncClipboard:跨平台&网络的剪贴板同步方案

至此,就可以试试具体效果了, mac端复制,手机端就已经提示复制到剪贴板了。

软件获取

软件源码:点击进入

1、本站所有资源文章出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。

2、本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。

发表评论

邮箱地址不会被公开。 必填项已用*标注