@@ -1278,7 +1278,19 @@ export default class GMApi extends GM_Base {
12781278 @GMContext . API ( { } )
12791279 GM_setClipboard ( data : string , info ?: GMTypes . GMClipboardInfo , cb ?: ( ) => void ) {
12801280 if ( this . isInvalidContext ( ) ) return ;
1281- this . sendMessage ( "GM_setClipboard" , [ data , info ] )
1281+ // 物件参数意义不明。日后再检视特殊处理
1282+ // 未支持 TM4.19+ application/octet-stream
1283+ // 参考: https://github.com/Tampermonkey/tampermonkey/issues/1250
1284+ let mimetype : string | undefined ;
1285+ if ( typeof info === "object" && info ?. mimetype ) {
1286+ mimetype = info . mimetype ;
1287+ } else {
1288+ mimetype = ( typeof info === "string" ? info : info ?. type ) || "text/plain" ;
1289+ if ( mimetype === "text" ) mimetype = "text/plain" ;
1290+ else if ( mimetype === "html" ) mimetype = "text/html" ;
1291+ }
1292+ data = `${ data } ` ; // 强制 string type
1293+ this . sendMessage ( "GM_setClipboard" , [ data , mimetype ] )
12821294 . then ( ( ) => {
12831295 if ( typeof cb === "function" ) {
12841296 cb ( ) ;
@@ -1294,7 +1306,11 @@ export default class GMApi extends GM_Base {
12941306 @GMContext . API ( { depend : [ "GM_setClipboard" ] } )
12951307 [ "GM.setClipboard" ] ( data : string , info ?: string | { type ?: string ; mimetype ?: string } ) : Promise < void > {
12961308 if ( this . isInvalidContext ( ) ) return new Promise < void > ( ( ) => { } ) ;
1297- return this . sendMessage ( "GM_setClipboard" , [ data , info ] ) ;
1309+ return new Promise < void > ( ( resolve ) => {
1310+ this . GM_setClipboard ( data , info , ( ) => {
1311+ resolve ( ) ;
1312+ } ) ;
1313+ } ) ;
12981314 }
12991315
13001316 @GMContext . API ( )
0 commit comments