Site Notice

hello, world

Difference between revisions of "Github CDN"

From Project-EPB Commons
m ([InPageEdit] →‎调用: 没有编辑摘要)
Line 6: Line 6:
 
== 调用 ==
 
== 调用 ==
 
<html>
 
<html>
<input id="show" readonly onclick="this.selected = true" style="width:96%">https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.js</input>
+
<div class="in-page-edit">
<form class="in-page-edit" id="myForm" onkeyup="getlink()">
+
<input id="showUrl" readonly onclick="this.selected = true" style="width:80%"></input><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 13: 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() {
+
window.RLQ = window.RLQ || [];
   var formData = '?' + $('#myForm').serialize();
+
RLQ.push(function (purge) {
  var para = function (i) { return mw.util.getParamValue(i, formData) };
+
   $('showUrl').val('https://cdn.jsdelivr.net/gh/...');
  var url = 'https://cdn.jsdelivr.net/gh';
+
  $('#dataForm').keyup(function () {
  url += '/' + para('user');
+
    var url = '/',
  url += '/' + para('repo');
+
      $this = $(this),
  if (para('version') !== '') url += '/' + para('version');
+
      formData = '?' + $this.serialize(),
  url += '/' + file;
+
      para = function (i) { return mw.util.getParamValue(i, formData) },
   $('#show').val(url);
+
      user = '/' + para('user'),
}
+
      repo = '/' + para('repo'),
 +
      version = para('version') !== '' ? '@' + para('version') : '',
 +
      file = '/' + para('file');
 +
    $('showUrl').val('https://cdn.jsdelivr.net/gh' + url);
 +
    $('#purgeBtn').attr('data-url', 'https://purge.jsdelivr.net/gh' + url);
 +
  });
 +
   $('#purgeBtn').click(function () {
 +
    var $this = $(this),
 +
      url = $this.attr('data-url');
 +
    if (url !== undefined && url !== '') {
 +
      $this.attr('disabled', 'disabled');
 +
      $.get(url).done(res => {
 +
        console.log(res);
 +
      }).fail(err => {
 +
        console.error(err);
 +
      }).always(() => {
 +
        $this.attr('disabled', false);
 +
      })
 +
    }
 +
  });
 +
});
 
</script>
 
</script>
 
</html>
 
</html>

Revision as of 01:29, 15 August 2020

jsDeliver

用法

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

调用

<html> <div class="in-page-edit"> <input id="showUrl" readonly onclick="this.selected = true" style="width:80%"></input><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> window.RLQ = window.RLQ || []; RLQ.push(function (purge) {

 $('showUrl').val('https://cdn.jsdelivr.net/gh/...');
 $('#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');
   $('showUrl').val('https://cdn.jsdelivr.net/gh' + url);
   $('#purgeBtn').attr('data-url', 'https://purge.jsdelivr.net/gh' + url);
 });
 $('#purgeBtn').click(function () {
   var $this = $(this),
     url = $this.attr('data-url');
   if (url !== undefined && url !== '') {
     $this.attr('disabled', 'disabled');
     $.get(url).done(res => {
       console.log(res);
     }).fail(err => {
       console.error(err);
     }).always(() => {
       $this.attr('disabled', false);
     })
   }
 });

}); </script> </html>