FP2 Icon Loader

Icon loader from local images for FPv2 icon editor.

当前为 2016-06-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name FP2 Icon Loader
// @author       Creec Winceptor
// @description  Icon loader from local images for FPv2 icon editor.
// @namespace https://greasyfork.org/users/3167
// @grant none
// @include http://facepunchforum.azurewebsites.net*
// @include https://facepunchforum.azurewebsites.net*
// @run-at document-idle
// @version 0.0.1.20160602080001
// ==/UserScript==

function Load(retries)
{

  	var tools_panel = document.getElementsByClassName("panel tools")[0];
  	var text_input = document.getElementsByName("textinput")[1];
	
	if (tools_panel && text_input)
    {
      var file_input = document.createElement("input");
      file_input.type = "file";
      file_input.id = "file_input";


      var hr_break = document.createElement("hr");
      tools_panel.appendChild(hr_break);

      tools_panel.appendChild(file_input);
      
      file_input.onchange = function(e) {

          var res = 16;
          var URL = window.webkitURL || window.URL;
          var url = URL.createObjectURL(e.target.files[0]);
          var img = new Image();


          img.src = url;

          img.onload = function() {


              pixelarray = []; 
              if(!img.canvas) {
                  img.canvas = $('<canvas />')[0];
                  img.canvas.width = res;
                  img.canvas.height = res;
                  img.canvas.getContext('2d').drawImage(img, 0, 0, res, res);

              }



              var count = 0;
              for (var x=0; x<res; x++)
              {
                  for (var y=0; y<res; y++)
                {
                  var pixelData = img.canvas.getContext('2d').getImageData(y, x, 1, 1).data;
                  pixelarray[count] = Math.round(pixelData[0]/256 * 9) + Math.round(pixelData[1]/256 * 9) * 10 + Math.round(pixelData[2]/256 * 9) * 100 + 1;

                  if (pixelData[3]==0)
                  {
                      pixelarray[count] = 0;
                  }
                  count++;

                }
              }
              
              text_input.value = EncodeIconData(pixelarray);
              text_input.dispatchEvent(new Event('change'));
          }
      };
  		
	}
  	else
    {
      	if (retries>0)
        {
          	setTimeout(function() {
                  Load(retries-1);  
            }, 500)
        }
    	else
        {
          	console.log("failed to load");
        }
    }
}
Load(10);