Site Notice

hello, world

Difference between revisions of "Github CDN"

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
([InPageEdit] →‎调用: 没有编辑摘要)
 
(9 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
== 调用 ==
 
== 调用 ==
<html><pre id="show">https://cdn.jsdelivr.net/gh/<span id="user">dragon-fish</span>/<span id="repo">inpageedit-v2</span>/<span id="version">master</span>/<span id="file">script.js</span></pre>
+
<html>
<form class="in-page-edit" id="myForm" onkeyup="getlink()">
+
<div class="in-page-edit">
 +
<input id="showUrl" readonly onclick="this.select()" style="width:80%"></input> <a href="javascript:;" id="viewBtn"><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="user" value="dragon-fish"/></label><br/>
 
<label>仓库:<br/><input name="repo" value="inpageedit-v2"/></label><br/>
 
<label>仓库:<br/><input name="repo" value="inpageedit-v2"/></label><br/>
Line 12: Line 14:
 
<label>文件:<br/><input name="file" value="script.js"/></label>
 
<label>文件:<br/><input name="file" value="script.js"/></label>
 
</form>
 
</form>
 +
</div>
 
<script>
 
<script>
function getlink(){
+
!(function () {
   var formData = '?' + $('#myForm').serialize();
+
   var _interval = setInterval(function () {
  var para = function(a){return mw.util.getParamValue(a,formData)};
+
    if (typeof $ !== 'function') return;
  $('#show > span').text(function(){
+
    clearInterval(_interval);
    var $this = $(this),
+
    $('#showUrl').val('Waiting for typing...');
       id = $this.attr('id');
+
    $('#dataForm').keyup(function () {
     return para(id);
+
      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://cdn.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 => {
 +
          ssi_modal.notify('', {
 +
            title: 'Request done',
 +
            content: '<pre>' + JSON.stringify(res, null, 2) + '</pre>',
 +
            className: 'in-page-edit'
 +
          })
 +
        }).fail(err => {
 +
          console.error(err);
 +
          ssi_modal.notify('error', {
 +
            title: 'Request failed',
 +
            content: '<pre>' + JSON.stringify(err, null, 2) + '</pre>',
 +
            className: 'in-page-edit'
 +
          })
 +
        }).always(() => {
 +
          $this.attr('disabled', false);
 +
        })
 +
      }
 +
     });
 +
   }, 200);
 +
})();
 
</script>
 
</script>
 
</html>
 
</html>

Latest revision as of 01:53, 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:;" id="viewBtn"><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('Waiting for typing...');
   $('#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://cdn.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 => {
         ssi_modal.notify('', {
           title: 'Request done',
           content: '<pre>' + JSON.stringify(res, null, 2) + '</pre>',
           className: 'in-page-edit'
         })
       }).fail(err => {
         console.error(err);
         ssi_modal.notify('error', {
           title: 'Request failed',
           content: '<pre>' + JSON.stringify(err, null, 2) + '</pre>',
           className: 'in-page-edit'
         })
       }).always(() => {
         $this.attr('disabled', false);
       })
     }
   });
 }, 200);

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