Site Notice

hello, world

Difference between revisions of "Github CDN"

From Project-EPB Commons
([InPageEdit] →‎调用: 没有编辑摘要)
m ([InPageEdit] →‎调用: 没有编辑摘要)
Line 7: Line 7:
 
<html>
 
<html>
 
<div class="in-page-edit">
 
<div class="in-page-edit">
<input id="showUrl" readonly onclick="this.selected = true" style="width:80%"></input><a href="javascript:;" class="btn btn-primary">view</a><button id="purgeBtn" class="btn btn-danger">purge</button>
+
<input id="showUrl" readonly onclick="this.select()" style="width:80%"></input> <a href="javascript:;"><button class="btn btn-primary">view</button></a> <button id="purgeBtn" class="btn btn-danger">purge</button>
 
<form id="dataForm">
 
<form id="dataForm">
 
<label>用户:<br/><input name="user" value="dragon-fish"/></label><br/>
 
<label>用户:<br/><input name="user" value="dragon-fish"/></label><br/>
Line 20: Line 20:
 
     if (typeof $ !== 'function') return;
 
     if (typeof $ !== 'function') return;
 
     clearInterval(_interval);
 
     clearInterval(_interval);
     $('#showUrl').val('https://cdn.jsdelivr.net/gh/...');
+
     $('#showUrl').val('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.js');
 
     $('#dataForm').keyup(function () {
 
     $('#dataForm').keyup(function () {
 
       var url = '',
 
       var url = '',

Revision as of 01:49, 15 August 2020

jsDeliver

用法

https://cdn.jsdelivr.net/gh/用户/仓库@分支/文件名

调用

<html> <div class="in-page-edit"> <input id="showUrl" readonly onclick="this.select()" style="width:80%"></input> <a href="javascript:;"><button class="btn btn-primary">view</button></a> <button id="purgeBtn" class="btn btn-danger">purge</button> <form id="dataForm"> <label>用户:<br/><input name="user" value="dragon-fish"/></label><br/> <label>仓库:<br/><input name="repo" value="inpageedit-v2"/></label><br/> <label>分支:<br/><input name="version" value="master"/></label><br/> <label>文件:<br/><input name="file" value="script.js"/></label> </form> </div> <script> !(function () {

 var _interval = setInterval(function () {
   if (typeof $ !== 'function') return;
   clearInterval(_interval);
   $('#showUrl').val('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.js');
   $('#dataForm').keyup(function () {
     var url = '',
       $this = $(this),
       formData = '?' + $this.serialize(),
       para = function (i) { return mw.util.getParamValue(i, formData) },
       user = '/' + para('user'),
       repo = '/' + para('repo'),
       version = para('version') !== '' ? '@' + para('version') : '',
       file = '/' + para('file');
     url += user + repo + version + file;
     $('#showUrl').val('https://cdn.jsdelivr.net/gh' + url);
     $('#viewBtn').attr({ 'href': 'https://purge.jsdelivr.net/gh' + url, target: '_blank' });
     $('#purgeBtn').attr('data-url', 'https://purge.jsdelivr.net/gh' + url);
   });
   $('#purgeBtn').click(function () {
     var $this = $(this),
       url = $this.attr('data-url');
     if (url) {
       $this.attr('disabled', 'disabled');
       $.get(url).done(res => {
         console.log(res);
       }).fail(err => {
         console.error(err);
       }).always(() => {
         $this.attr('disabled', false);
       })
     }
   });
 }, 200);

})(); </script> </html>