Greasy Fork

Greasy Fork is available in English.

IMDB List Importer

Import list of titles, people or characters in the imdb list

当前为 2016-09-29 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        IMDB List Importer
// @namespace   Neinei0k_imdb
// @include     http://www.imdb.com/list/edit*
// @version     3.0
// @grant       none
// @description Import list of titles, people or characters in the imdb list
// ==/UserScript==

unsafeWindow.create_list = function() {
  var re
  if (document.getElementsByClassName('list_characters').length != 0) {
    re = /ch[0-9]{7}/
  } else if (document.getElementsByClassName('list_people').length != 0) {
    re = /nm[0-9]{7}/
  } else if (document.getElementsByClassName('list_titles').length != 0) {
    re = /tt[0-9]{7}/
  } else {
    return []
  }
    
  var text = document.getElementById('import_list_field').value
  var list = []
  var e
  while ((e = re.exec(text)) != null) {
    var rer = new RegExp(e[0], 'g')
    text = text.replace(rer, '')
    list.push(e[0])
  }
  
  return list
}

unsafeWindow.add_list = function(list) {
  var length = list.length
  var list_id = /ls[0-9]{1,}/.exec(location.href)[0]
  
  var ready_e = document.getElementById('import_list_ready')
  var ready = 0
  function showReady() {
    if (this.readyState == 4 && this.status == 200) {
      ready += 1
      ready_e.innerHTML = "Ready "+ready+" of "+length+"."
    }
  }
  
  for (var i = 0; i < length; i++) {
    var xhttp = new XMLHttpRequest()
    console.log('Add element '+(i+1)+': '+list[i])
    xhttp.onreadystatechange = showReady
    xhttp.open('POST', '/list/_ajax/edit', true)
    xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
    xhttp.send("const="+list[i]+"&list_id="+list_id)
  }
}

var field = document.createElement('textarea')
field.setAttribute('id','import_list_field')
var button = document.createElement('button')
button.setAttribute('onclick', 'var list = create_list(); add_list(list)')
button.textContent = 'Import list'
var readyText = document.createElement('div')
readyText.setAttribute('id','import_list_ready')
readyText.innerHTML = "Insert text with id's in the field above and press button 'Import list'"

var main = document.getElementById('main').childNodes[3]
main.insertBefore(field, main.childNodes[7])
main.insertBefore(readyText, main.childNodes[8])
main.insertBefore(button, main.childNodes[9])