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

解码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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证