duanshanduo3363 2018-04-08 18:09
浏览 1044
已采纳

解码base64 URL并嵌入HTML

I want make like this http://www.jredtna.com/read/?hash=cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=

(You can't see iframe because website using cookies to check if you coming from another website).

So please join here http://halqat.online/video/watch.php?vid=6f673f4c5 and click red play button to see what I mean.

When decode hash= by base64:

cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=

will give us like this:

player 1 => https://www.youtube.com/embed/fh0QD-WWrcc

player 2 => https://www.youtube.com/embed/2MpUj-Aua48

My question is how I can do like that:

Get hash=Base64URL

Decode it and split "player 1" and "youtube url" by =>

Put data inside html like this

<div class="embeding">
  <ul>
      <li><a data-src="https://www.youtube.com/embed/fh0QD-WWrcc">player 1</a></li>
      <li><a data-src="https://www.youtube.com/embed/2MpUj-Aua48">player 2</a></li>
  </ul>
</div>

and auto add li a if find another players

  • 写回答

1条回答 默认 最新

  • duanliao3826 2018-04-08 18:47
    关注

    I use splice method to make an array and then from this array I get the youtube url's strings via split method.

    function decodeBase_64(arg){ 
      var decodedData=window.atob(arg);
      var a;
      var c=[];  
      for(var i=0;i<decodedData.split('=>').length;i++){
        if(decodedData.split('=>')[i].length>10){      
          a=decodedData.split('=>')[i];
          a=a.substr(0, 42);
          c.push(a);
        }
      }
       return c; 
    }
    document.getElementById('player_1').setAttribute('data-src',decodeBase_64('cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=')[0] );
    document.getElementById('player_2').setAttribute('data-src',decodeBase_64('cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=')[1] );
    
    console.log(decodeBase_64('cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg='));
    console.log(decodeBase_64('cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=')[0]);
    console.log(decodeBase_64('cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=')[1]);
    <div class="embeding">
      <ul>
          <li><a data-src="" id="player_1">player 1</a></li>
          <li><a data-src="" id="player_2">player 2</a></li>
      </ul>
    </div>

    Check the console to see the c array

    For the second issue..Get the her via window.location.href and then

    var str='http://www.jredtna.com/read/?hash=cGxheWVyIDEgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvZmgwUUQtV1dyY2MKcGxheWVyIDIgPT4gaHR0cHM6Ly93d3cueW91dHViZS5jb20vZW1iZWQvMk1wVWotQXVhNDg=';
    str=str.substring(str.indexOf("hash="));
    str=str.replace('hash=','');
    console.log(str);

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?